Files
SAE-BUT2/apps/backend/app/Notifications/UserRegistered.php
T

42 lines
1016 B
PHP
Executable File

<?php
namespace App\Notifications;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Notification;
class UserRegistered extends Notification implements ShouldBroadcast
{
use Queueable;
public function __construct(public User $user) {}
public function via($notifiable): array
{
$channels = [];
if ($notifiable->web_notifications) {
$channels[] = 'database';
$channels[] = 'broadcast';
}
return $channels;
}
public function toDatabase($notifiable): array
{
return [
'message' => "Nouvelle demande d'inscription : {$this->user->name} {$this->user->lastname}",
'user_id' => $this->user->id,
];
}
public function toBroadcast($notifiable): BroadcastMessage
{
return new BroadcastMessage($this->toDatabase($notifiable));
}
}