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