diff --git a/app/Http/Controllers/EventAttendeesController.php b/app/Http/Controllers/EventAttendeesController.php index f68c31d7..e77f00b6 100644 --- a/app/Http/Controllers/EventAttendeesController.php +++ b/app/Http/Controllers/EventAttendeesController.php @@ -745,7 +745,7 @@ class EventAttendeesController extends MyBaseController 'email_logo' => $attendee->event->organiser->full_logo_path, ]; - if ($request->get('notify_attendee') == '1') { + if ($request->get('notify_attendee') == '1') {//todo queue this mail Mail::send('Emails.notifyCancelledAttendee', $data, function ($message) use ($attendee) { $message->to($attendee->email, $attendee->full_name) ->from(config('attendize.outgoing_email_noreply'), $attendee->event->organiser->name) diff --git a/app/Http/Controllers/HelpDeskController.php b/app/Http/Controllers/HelpDeskController.php index 4ca1bbad..f5b3acbe 100644 --- a/app/Http/Controllers/HelpDeskController.php +++ b/app/Http/Controllers/HelpDeskController.php @@ -9,7 +9,9 @@ use App\Http\Requests\HelpTicketRequest; use App\Models\HelpTicket; use App\Models\HelpTicketComment; use App\Models\HelpTopic; +use App\Notifications\TicketReceived; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Notification; class HelpDeskController extends Controller { @@ -37,7 +39,7 @@ class HelpDeskController extends Controller try{ - $ticekt = HelpTicket::create([ + $ticket = HelpTicket::create([ 'name' => $request->get('name'), 'email' => $request->get('email'), 'text' => $request->get('text'), @@ -46,8 +48,21 @@ class HelpDeskController extends Controller 'ticket_category_id' => $request->get('topic'), 'attachment' => $request->file('attachment') ]); - //todo fire event notify admin by mail, attachment - return redirect()->route('help.show',['code' => $ticekt->code]); + + + /** + * Notify customer that ticket is received; + */ + $ticket->notify(new TicketReceived($ticket)); + + /** + * Notify administrators that ticket is arrived; + */ + $administrators = User::where('is_admin',1)->get(['id','email']); + + Notification::send($administrators, new TicketReceived($ticket)); + + return redirect()->route('help.show',['code' => $ticket->code]); } catch (\Exception $exception){ Log::error($exception); diff --git a/app/Models/HelpTicket.php b/app/Models/HelpTicket.php index d6532966..7090cd8b 100644 --- a/app/Models/HelpTicket.php +++ b/app/Models/HelpTicket.php @@ -4,12 +4,13 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; use Backpack\CRUD\CrudTrait; +use Illuminate\Notifications\Notifiable; use Illuminate\Support\Str; class HelpTicket extends Model { use CrudTrait; - + use Notifiable; /* |-------------------------------------------------------------------------- | GLOBAL VARIABLES @@ -55,6 +56,9 @@ class HelpTicket extends Model |-------------------------------------------------------------------------- */ + public function getOwnerAttribute(){ + return $this->name ?? $this->email; + } /* |-------------------------------------------------------------------------- | MUTATORS diff --git a/app/Models/HelpTicketComment.php b/app/Models/HelpTicketComment.php index aeba750b..20240666 100644 --- a/app/Models/HelpTicketComment.php +++ b/app/Models/HelpTicketComment.php @@ -39,6 +39,10 @@ class HelpTicketComment extends Model public function ticket(){ return $this->belongsTo(HelpTicket::class); } + + public function user(){ + return $this->belongsTo(User::class); + } /* |-------------------------------------------------------------------------- | SCOPES @@ -51,6 +55,9 @@ class HelpTicketComment extends Model |-------------------------------------------------------------------------- */ + public function getOwnerAttribute(){ + return $this->user->full_name ?? $this->name; + } /* |-------------------------------------------------------------------------- | MUTATORS diff --git a/app/Notifications/TicketReceived.php b/app/Notifications/TicketReceived.php new file mode 100644 index 00000000..272e73cb --- /dev/null +++ b/app/Notifications/TicketReceived.php @@ -0,0 +1,70 @@ +ticket = $ticket; + } + + /** + * Get the notification's delivery channels. + * + * @param mixed $notifiable + * @return array + */ + public function via($notifiable) + { + return $notifiable instanceof HelpTicket ? ['mail'] : ['mail','database']; + } + + /** + * Get the mail representation of the notification. + * + * @param mixed $notifiable + * @return \Illuminate\Notifications\Messages\MailMessage + */ + public function toMail($notifiable) + { + if($notifiable instanceof HelpTicket){ + return (new MailMessage) + ->line('The introduction to the notification.') + ->action('Notification Action', route('help.show',['code' => $this->ticket->code])) + ->line('Thank you for using our application!'); + } + else + return (new MailMessage) + ->line('You have new ticket') + ->action('Notification Action', route('ticket.replay',['id'=>$this->ticket->id])) + ->line('Thank you for using our application!'); + } + + /** + * Get the array representation of the notification. + * + * @param mixed $notifiable + * @return array + */ + public function toDatabase($notifiable) + { + return $this->ticket->toArray(); + } +} diff --git a/app/Notifications/UserResetPassword.php b/app/Notifications/UserResetPassword.php index a68e309c..6e39ba0f 100644 --- a/app/Notifications/UserResetPassword.php +++ b/app/Notifications/UserResetPassword.php @@ -7,7 +7,7 @@ use Illuminate\Notifications\Notification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Messages\MailMessage; -class UserResetPassword extends Notification +class UserResetPassword extends Notification implements ShouldQueue { use Queueable; diff --git a/database/migrations/2020_05_06_153931_create_notifications_table.php b/database/migrations/2020_05_06_153931_create_notifications_table.php new file mode 100644 index 00000000..fb16d5bc --- /dev/null +++ b/database/migrations/2020_05_06_153931_create_notifications_table.php @@ -0,0 +1,35 @@ +uuid('id')->primary(); + $table->string('type'); + $table->morphs('notifiable'); + $table->text('data'); + $table->timestamp('read_at')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('notifications'); + } +} diff --git a/resources/views/admin/HelpDeskTicket.blade.php b/resources/views/admin/HelpDeskTicket.blade.php index b606dc78..cb76b28e 100644 --- a/resources/views/admin/HelpDeskTicket.blade.php +++ b/resources/views/admin/HelpDeskTicket.blade.php @@ -64,7 +64,7 @@
+ @foreach($entry->comments as $comment)
-
+
+ @endforeach
+ diff --git a/resources/views/desktop/Pages/HelpDeskCreateForm.blade.php b/resources/views/desktop/Pages/HelpDeskCreateForm.blade.php index 63206eeb..44e1e363 100644 --- a/resources/views/desktop/Pages/HelpDeskCreateForm.blade.php +++ b/resources/views/desktop/Pages/HelpDeskCreateForm.blade.php @@ -51,11 +51,12 @@
{!! Form::label('attachment', trans("ClientSide.attachment"), array('class'=>'control-label')) !!} {!! Form::file('attachment') !!} + @if($errors->has('attachment')) +

{{ $errors->first('attachment') }}

+ @endif
{!! Form::submit(trans("ClientSide.create_ticket"), ['class'=>"btn btn-success"]) !!} - @if($errors->has('attachment')) -

{{ $errors->first('attachment') }}

- @endif +