From b41f11f7cc0ec339feaa6a1d0b8c51f098c9c6bb Mon Sep 17 00:00:00 2001 From: merdan Date: Wed, 6 May 2020 20:53:50 +0500 Subject: [PATCH] help desk notification ticketReceived --- .../Admin/HelpTicketCrudController.php | 20 ++++++ app/Notifications/TicketCommented.php | 65 +++++++++++++++++++ routes/backpack/custom.php | 2 +- 3 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 app/Notifications/TicketCommented.php diff --git a/app/Http/Controllers/Admin/HelpTicketCrudController.php b/app/Http/Controllers/Admin/HelpTicketCrudController.php index d46f506e..c2f6e17f 100644 --- a/app/Http/Controllers/Admin/HelpTicketCrudController.php +++ b/app/Http/Controllers/Admin/HelpTicketCrudController.php @@ -2,13 +2,17 @@ namespace App\Http\Controllers\Admin; +use App\Http\Requests\HelpTicketCommentRequest; use App\Models\HelpTicket; +use App\Models\HelpTicketComment; +use App\Notifications\TicketCommented; use Backpack\CRUD\app\Http\Controllers\CrudController; // VALIDATION: change the requests to match your own file names if you need form validation use App\Http\Requests\HelpTicketRequest as StoreRequest; use App\Http\Requests\HelpTicketRequest as UpdateRequest; use Backpack\CRUD\CrudPanel; +use Illuminate\Support\Facades\Notification; /** * Class HelpTicletCrudController @@ -97,4 +101,20 @@ class HelpTicketCrudController extends CrudController ->with('entry',$entry) ->with('crud',$this->crud); } + + public function replayPost(HelpTicketCommentRequest $request, $ticket_id){ + $ticket = HelpTicket::findOrFail($ticket_id,['id','email','name']); + + $comment = HelpTicketComment::create([ + 'help_ticket_id' => $ticket_id, + 'text' => $request->text, + 'name' => auth()->user()->full_name, + 'user_id' => auth()->id() + ]); + + Notification::route('mail', $ticket->email) + ->notify(new TicketCommented($comment)); + + return redirect()->route('ticket.replay',['id'=>$ticket_id]); + } } diff --git a/app/Notifications/TicketCommented.php b/app/Notifications/TicketCommented.php new file mode 100644 index 00000000..23a11268 --- /dev/null +++ b/app/Notifications/TicketCommented.php @@ -0,0 +1,65 @@ +comment = $comment; + // + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toMail($notifiable) + { + return (new MailMessage) + ->line('The introduction to the notification.') + ->action('Notification Action', url('/')) + ->line('Thank you for using our application!'); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toArray($notifiable) + { + return [ + // + ]; + } +} diff --git a/routes/backpack/custom.php b/routes/backpack/custom.php index 63bc6ac9..18bb806a 100644 --- a/routes/backpack/custom.php +++ b/routes/backpack/custom.php @@ -25,5 +25,5 @@ Route::group([ CRUD::resource('helpTopic','HelpTopicCrudController'); CRUD::resource('helpTicket','HelpTicketCrudController'); Route::get('helpTicket/{id}/replay', 'HelpTicketCrudController@replay')->name('ticket.replay'); - Route::post('helpTicket/{id}/replay', 'HelpTicketCrudController@replay')->name('ticket.replay.post'); + Route::post('helpTicket/{id}/replay', 'HelpTicketCrudController@replayPost')->name('ticket.replay.post'); }); // this should be the absolute last line of this file