ResetPassword.php 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Illuminate\Auth\Notifications;
  3. use Illuminate\Support\Facades\Lang;
  4. use Illuminate\Notifications\Notification;
  5. use Illuminate\Notifications\Messages\MailMessage;
  6. class ResetPassword extends Notification
  7. {
  8. /**
  9. * The password reset token.
  10. *
  11. * @var string
  12. */
  13. public $token;
  14. /**
  15. * The callback that should be used to build the mail message.
  16. *
  17. * @var \Closure|null
  18. */
  19. public static $toMailCallback;
  20. /**
  21. * Create a notification instance.
  22. *
  23. * @param string $token
  24. * @return void
  25. */
  26. public function __construct($token)
  27. {
  28. $this->token = $token;
  29. }
  30. /**
  31. * Get the notification's channels.
  32. *
  33. * @param mixed $notifiable
  34. * @return array|string
  35. */
  36. public function via($notifiable)
  37. {
  38. return ['mail'];
  39. }
  40. /**
  41. * Build the mail representation of the notification.
  42. *
  43. * @param mixed $notifiable
  44. * @return \Illuminate\Notifications\Messages\MailMessage
  45. */
  46. public function toMail($notifiable)
  47. {
  48. if (static::$toMailCallback) {
  49. return call_user_func(static::$toMailCallback, $notifiable, $this->token);
  50. }
  51. return (new MailMessage)
  52. ->subject(Lang::getFromJson('Reset Password Notification'))
  53. ->line(Lang::getFromJson('You are receiving this email because we received a password reset request for your account.'))
  54. ->action(Lang::getFromJson('Reset Password'), url(config('app.url').route('password.reset', $this->token, false)))
  55. ->line(Lang::getFromJson('If you did not request a password reset, no further action is required.'));
  56. }
  57. /**
  58. * Set a callback that should be used when building the notification mail message.
  59. *
  60. * @param \Closure $callback
  61. * @return void
  62. */
  63. public static function toMailUsing($callback)
  64. {
  65. static::$toMailCallback = $callback;
  66. }
  67. }