osb/app/Notifications/ResetPasswordNotification.php

81 lines
1.8 KiB
PHP
Raw Normal View History

2018-08-07 04:26:33 +00:00
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class ResetPasswordNotification extends Notification
{
use Queueable;
2020-01-22 10:05:31 +00:00
/**
* The password reset token.
*
* @var string
*/
public $token;
/**
* The callback that should be used to build the mail message.
*
* @var \Closure|null
*/
public static $toMailCallback;
2018-08-07 04:26:33 +00:00
/**
2020-01-22 10:05:31 +00:00
* Create a notification instance.
2018-08-07 04:26:33 +00:00
*
2020-01-22 10:05:31 +00:00
* @param string $token
2018-08-07 04:26:33 +00:00
* @return void
*/
public function __construct($token)
{
2020-01-22 10:05:31 +00:00
$this->token = $token;
2018-08-07 04:26:33 +00:00
}
/**
2020-01-22 10:05:31 +00:00
* Get the notification's channels.
2018-08-07 04:26:33 +00:00
*
* @param mixed $notifiable
2020-01-22 10:05:31 +00:00
* @return array|string
2018-08-07 04:26:33 +00:00
*/
public function via($notifiable)
{
return ['mail'];
}
/**
2020-01-22 10:05:31 +00:00
* Build the mail representation of the notification.
2018-08-07 04:26:33 +00:00
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
2020-01-22 10:05:31 +00:00
if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
}
2018-08-07 04:26:33 +00:00
2020-01-22 10:05:31 +00:00
return (new MailMessage)
->markdown('email.user.passwordreset',[
'site'=>config('SITE_SETUP'),
'user'=>$notifiable,
'reset_link'=>route('password.reset',$this->token,true),
]);
}
/**
* Set a callback that should be used when building the notification mail message.
*
* @param \Closure $callback
* @return void
*/
public static function toMailUsing($callback)
{
static::$toMailCallback = $callback;
2018-08-07 04:26:33 +00:00
}
2020-01-22 10:05:31 +00:00
}