Skip to content

Commit

Permalink
Merge pull request #147 from nidhalkratos/master
Browse files Browse the repository at this point in the history
Makes The model, controller, and the screenshot storage disk configurable through the config
  • Loading branch information
mydnic authored Jan 11, 2025
2 parents 8813f37 + 6a3308a commit 531b69e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
39 changes: 39 additions & 0 deletions config/kustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,43 @@
*/

'screenshot' => false,

/*
|--------------------------------------------------------------------------
| Screenshot Storage Disk
|--------------------------------------------------------------------------
|
| Define which storage disk should be used to store the feedback screenshots.
| This should be one of the disk names from your config/filesystems.php.
| If not specified, the default disk will be used.
|
*/

'screenshot_disk' => null,

/*
|--------------------------------------------------------------------------
| Feedback Model
|--------------------------------------------------------------------------
|
| This is the model class that will be used for feedback records. You can
| override this to use your own model class if you need to extend or
| modify the base feedback functionality.
|
*/

'model' => \Mydnic\Kustomer\Models\Feedback::class,

/*
|--------------------------------------------------------------------------
| Feedback Controller
|--------------------------------------------------------------------------
|
| This is the controller class that will handle feedback submissions.
| You can override this to use your own controller if you need to
| modify the base feedback handling functionality.
|
*/

'controller' => \Mydnic\Kustomer\Http\Controllers\FeedbackController::class,
];
3 changes: 2 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

use Illuminate\Support\Facades\Route;

Route::post('feedback', 'FeedbackController@store')->name('feedback.store');
Route::post('/feedback', [config('kustomer.controller'), 'store'])
->name('feedback.store');
3 changes: 1 addition & 2 deletions src/Events/NewFeedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Mydnic\Kustomer\Feedback;

class NewFeedback implements ShouldBroadcast
{
Expand All @@ -22,7 +21,7 @@ class NewFeedback implements ShouldBroadcast
*
* @return void
*/
public function __construct(Feedback $feedback)
public function __construct($feedback)
{
$this->feedback = $feedback;
}
Expand Down
13 changes: 9 additions & 4 deletions src/Http/Controllers/FeedbackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Mydnic\Kustomer\Feedback;
use Illuminate\Validation\Rule;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Storage;
Expand Down Expand Up @@ -38,7 +37,9 @@ protected function validates(Request $request)

protected function storeFeedback($data, Request $request)
{
$feedback = new Feedback;
$feedbackModel = config('kustomer.model');
$feedback = new $feedbackModel;

$feedback->type = $data['type'];
$feedback->message = $data['message'];
$feedback->user_info = $this->gatherUserInfo($request);
Expand All @@ -59,7 +60,7 @@ protected function gatherUserInfo(Request $request)
];
}

protected function dispatchEvent(Feedback $feedback)
protected function dispatchEvent($feedback)
{
event(new NewFeedback($feedback));
}
Expand All @@ -71,7 +72,11 @@ protected function saveScreenshot($base64Screenshot = null)
$image = str_replace('data:image/png;base64,', '', $image);
$image = str_replace(' ', '+', $image);
$imageName = microtime(true) . Str::random(4) . '.' . 'png';
if (Storage::put('screenshots/' . $imageName, base64_decode($image))) {

$disk = config('kustomer.screenshot_disk');
$storage = $disk ? Storage::disk($disk) : Storage::disk();

if ($storage->put('screenshots/' . $imageName, base64_decode($image))) {
return 'screenshots/' . $imageName;
}
}
Expand Down

0 comments on commit 531b69e

Please sign in to comment.