create TaskDeleted notification
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Mail\TaskParticipationCancelledMail;
|
||||
use App\Models\Event;
|
||||
use App\Models\Task;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Notifications\Messages\BroadcastMessage;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class TaskDeleted extends Notification implements ShouldBroadcast
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
public Task $task,
|
||||
public Event $event,
|
||||
) {}
|
||||
|
||||
public function via($notifiable): array
|
||||
{
|
||||
$channels = [];
|
||||
|
||||
if ($notifiable->web_notifications) {
|
||||
$channels[] = 'database';
|
||||
$channels[] = 'broadcast';
|
||||
}
|
||||
|
||||
if ($notifiable->email_notifications) {
|
||||
$channels[] = 'mail';
|
||||
}
|
||||
|
||||
return $channels;
|
||||
}
|
||||
|
||||
public function toDatabase($notifiable): array
|
||||
{
|
||||
return [
|
||||
'message' => "La tâche {$this->task->name} pour l'événement {$this->event->name} a été supprimée. Vous n'y participez donc plus.",
|
||||
'task_id' => $this->task->id,
|
||||
'event_id' => $this->event->id,
|
||||
];
|
||||
}
|
||||
|
||||
public function toBroadcast($notifiable): BroadcastMessage
|
||||
{
|
||||
return new BroadcastMessage($this->toDatabase($notifiable));
|
||||
}
|
||||
|
||||
public function toMail($notifiable): void
|
||||
{
|
||||
Mail::to($notifiable->email)->send(new TaskParticipationCancelledMail([
|
||||
'name' => $notifiable->name,
|
||||
'lastname' => $notifiable->lastname,
|
||||
'taskName' => $this->task->name,
|
||||
'start' => $this->event->start,
|
||||
'end' => $this->task->end,
|
||||
'eventName' => $this->event->name,
|
||||
]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user