45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\User;
|
|
use App\Mail\RegisterMail;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Notifications\Notification;
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
|
use Illuminate\Notifications\Messages\BroadcastMessage;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
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));
|
|
}
|
|
}
|