create UserRegistered notification
This commit is contained in:
@@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
// app/Notifications/UserRegistered.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';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($notifiable->email_notifications) {
|
||||||
|
$channels[] = 'mail';
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toMail($notifiable): MailMessage
|
||||||
|
{
|
||||||
|
Mail::to($notifiable->email)->send(new RegisterMail([
|
||||||
|
'adminName' => $notifiable->name,
|
||||||
|
'adminLastname'=> $notifiable->lastname,
|
||||||
|
'userName' => $this->user->name,
|
||||||
|
'userLastname' => $this->user->lastname,
|
||||||
|
]));
|
||||||
|
|
||||||
|
return (new MailMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user