Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save DarkGhostHunter/3133cd7d2eed7760065d13eaa6447b53 to your computer and use it in GitHub Desktop.

Select an option

Save DarkGhostHunter/3133cd7d2eed7760065d13eaa6447b53 to your computer and use it in GitHub Desktop.
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\URL;
class EmailChangeNotification extends Notification implements ShouldQueue
{
use Queueable;
/**
* The user Email
*
* @var string
*/
protected $userId;
/**
* Create a new notification instance.
*
* @param string $userId
*/
public function __construct(string $userId)
{
$this->userId = $userId;
}
/**
* 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(AnonymousNotifiable $notifiable)
{
return (new MailMessage)->markdown('mail.email-reset', [
'notifiable' => $notifiable,
'route' => $this->verifyRoute($notifiable)
]);
}
/**
* Returns the Reset URl to send in the Email
*
* @param AnonymousNotifiable $notifiable
* @return string
*/
protected function verifyRoute(AnonymousNotifiable $notifiable)
{
return URL::temporarySignedRoute('user.email-change-verify', 60 * 60, [
'user' => $this->userId,
'email' => $notifiable->routes['mail']
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment