Files
SAE-BUT2-backend/app/Notifications/VolunteerRoleUpdated.php
T

56 lines
1.4 KiB
PHP

<?php
namespace App\Notifications;
use App\Mail\UpdateRoleMail;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Support\Facades\Mail;
class VolunteerRoleUpdated extends Notification implements ShouldBroadcast
{
use Queueable;
public function __construct(public string $role) {}
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' => "Votre rôle a changé pour : {$this->role}",
'role' => $this->role,
];
}
public function toBroadcast($notifiable): BroadcastMessage
{
return new BroadcastMessage($this->toDatabase($notifiable));
}
public function toMail($notifiable): void
{
Mail::to($notifiable->email)->send(new UpdateRoleMail([
'name' => $notifiable->name,
'lastname' => $notifiable->lastname,
'role' => $this->role,
]));
}
}