blue-twilight/app/Notifications/ResetPassword.php

81 lines
1.8 KiB
PHP

<?php
namespace App\Notifications;
use App\Facade\UserConfig;
use App\Mail\MailableBase;
use App\Mail\ResetMyPassword;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class ResetPassword extends Notification
{
use Queueable;
/**
* The password reset token.
*
* @var string
*/
public $token;
/**
* Create a notification instance.
*
* @param string $token
* @return void
*/
public function __construct($token)
{
$this->token = $token;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
$drivers = [];
if (UserConfig::get('queue_emails'))
{
$drivers[] = QueueEmailDatabaseChannel::class;
}
else
{
$drivers[] = 'mail';
$drivers[] = SentEmailDatabaseChannel::class;
}
return $drivers;
}
public function toQueueEmailDatabase($notifiable)
{
return $this->toMail($notifiable)->buildEmailLog();
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage|MailableBase
*/
public function toMail($notifiable)
{
$notification = new ResetMyPassword($notifiable, $this->token);
// Set to and from properties accordingly
$notification->from(UserConfig::get('sender_address'), UserConfig::get('sender_name'));
$notification->to($notifiable->email, $notifiable->name);
return $notification;
}
}