Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes The model, controller, and the screenshot storage disk configurable through the config #147

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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