/ app / Notifications / TaskAssigned.php
TaskAssigned.php
 1  <?php
 2  
 3  namespace App\Notifications;
 4  
 5  use App\Models\Task;
 6  use App\Models\User;
 7  use Illuminate\Bus\Queueable;
 8  use Illuminate\Notifications\Notification;
 9  
10  class TaskAssigned extends Notification
11  {
12      use Queueable;
13  
14      private string $taskName;
15  
16      /**
17       * Create a new notification instance.
18       *
19       * @return void
20       */
21      public function __construct(public Task $task)
22      {
23          //
24      }
25  
26      /**
27       * Get the notification's delivery channels.
28       *
29       * @param  mixed  $notifiable
30       * @return array
31       */
32      public function via($notifiable)
33      {
34          return ['database'];
35      }
36  
37      /**
38       * Get the array representation of the notification.
39       *
40       * @param  mixed  $notifiable
41       * @return array
42       */
43      public function toArray($notifiable)
44      {
45          return [
46              'user_id' => $notifiable->id,
47              'title' => __('notifications.message-title.NewTask'),
48              'message' => $this->task->title,
49              'task_id' => $this->task->id,
50          ];
51      }
52  }