VerifyEmail.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Notifications\Email;
  3. use Illuminate\Notifications\Messages\MailMessage;
  4. use Illuminate\Notifications\Notification;
  5. use Illuminate\Support\Carbon;
  6. use Illuminate\Support\Facades\Config;
  7. use Illuminate\Support\Facades\Lang;
  8. use Illuminate\Support\Facades\URL;
  9. class VerifyEmail extends Notification
  10. {
  11. /**
  12. * The callback that should be used to build the mail message.
  13. *
  14. * @var \Closure|null
  15. */
  16. public static $toMailCallback;
  17. /**
  18. * Get the notification's channels.
  19. *
  20. * @param mixed $notifiable
  21. * @return array|string
  22. */
  23. public function via($notifiable)
  24. {
  25. return ['mail'];
  26. }
  27. /**
  28. * Build the mail representation of the notification.
  29. *
  30. * @param mixed $notifiable
  31. * @return \Illuminate\Notifications\Messages\MailMessage
  32. */
  33. public function toMail($notifiable)
  34. {
  35. $verificationUrl = $this->verificationUrl($notifiable);
  36. if (static::$toMailCallback) {
  37. return call_user_func(static::$toMailCallback, $notifiable, $verificationUrl);
  38. }
  39. return (new MailMessage)
  40. ->theme((app()->getLocale() == 'fa') ? 'rtl-theme' : 'default')
  41. ->greeting(Lang::get('mail.resetPassword.greeting'))
  42. ->salutation(Lang::get('mail.resetPassword.salutation'))
  43. ->subject(Lang::get('mail.verifyEmail.subject'))
  44. ->line(Lang::get('mail.verifyEmail.excerpt'))
  45. ->action(Lang::get('mail.verifyEmail.button'), $verificationUrl);
  46. }
  47. /**
  48. * Get the verification URL for the given notifiable.
  49. *
  50. * @param mixed $notifiable
  51. * @return string
  52. */
  53. protected function verificationUrl($notifiable)
  54. {
  55. return URL::temporarySignedRoute(
  56. 'verification.verify',
  57. Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
  58. [
  59. 'id' => $notifiable->getKey(),
  60. 'hash' => sha1($notifiable->getEmailForVerification()),
  61. ]
  62. );
  63. }
  64. /**
  65. * Set a callback that should be used when building the notification mail message.
  66. *
  67. * @param \Closure $callback
  68. * @return void
  69. */
  70. public static function toMailUsing($callback)
  71. {
  72. static::$toMailCallback = $callback;
  73. }
  74. }