app/Notifications/PasswordForgotten.php
<?php
namespace App\Notifications;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class PasswordForgotten extends Notification
{
use Queueable;
private User $user;
private string $url;
/**
* Create a new notification instance.
*
* @param User $user
*/
public function __construct(User $user, string $url)
{
$this->user = $user;
$this->url = $url;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)->action('Reset your password', $this->url);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'user_id' => $this->user->getKey(),
'token' => $this->user->password_reset_token,
];
}
}