49 lines
1.2 KiB
PHP
Executable File
49 lines
1.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Mail\VolunteerAssignToTaskMail;
|
|
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 VolunteerAssignedToTask 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';
|
|
}
|
|
|
|
return $channels;
|
|
}
|
|
|
|
public function toDatabase($notifiable): array
|
|
{
|
|
return [
|
|
'message' => "Vous avez été assigné à la tâche {$this->task->name} de l'événement {$this->event->name}.",
|
|
'task_id' => $this->task->id,
|
|
'event_id' => $this->event->id,
|
|
];
|
|
}
|
|
|
|
public function toBroadcast($notifiable): BroadcastMessage
|
|
{
|
|
return new BroadcastMessage($this->toDatabase($notifiable));
|
|
}
|
|
}
|