57 lines
1.6 KiB
PHP
Executable File
57 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Mail\TaskDateUpdateMail;
|
|
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 TaskDateUpdated extends Notification implements ShouldBroadcast
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(
|
|
public Task $task,
|
|
public Event $event,
|
|
public string $oldStart,
|
|
public string $oldEnd,
|
|
public string $newStart,
|
|
public string $newEnd,
|
|
) {}
|
|
|
|
public function via($notifiable): array
|
|
{
|
|
$channels = [];
|
|
|
|
if ($notifiable->web_notifications) {
|
|
$channels[] = 'database';
|
|
$channels[] = 'broadcast';
|
|
}
|
|
|
|
return $channels;
|
|
}
|
|
|
|
public function toDatabase($notifiable): array
|
|
{
|
|
return [
|
|
'message' => "La date de la tâche {$this->task->name} de l'événement {$this->event->name} a été mise à jour. Cette tâche aura maintenant lieu du {$this->newStart} au {$this->newEnd}.",
|
|
'task_id' => $this->task->id,
|
|
'event_id' => $this->event->id,
|
|
'old_start' => $this->oldStart,
|
|
'old_end' => $this->oldEnd,
|
|
'new_start' => $this->newStart,
|
|
'new_end' => $this->newEnd,
|
|
];
|
|
}
|
|
|
|
public function toBroadcast($notifiable): BroadcastMessage
|
|
{
|
|
return new BroadcastMessage($this->toDatabase($notifiable));
|
|
}
|
|
}
|