فهرست منبع

Custom notification for reset password

Bubka 5 سال پیش
والد
کامیت
5ec355dd9a
2فایلهای تغییر یافته به همراه37 افزوده شده و 0 حذف شده
  1. 25 0
      app/Notifications/ResetPassword.php
  2. 12 0
      app/User.php

+ 25 - 0
app/Notifications/ResetPassword.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Notifications;
+
+use Illuminate\Auth\Notifications\ResetPassword as Notification;
+use Illuminate\Notifications\Messages\MailMessage;
+
+class ResetPassword extends Notification
+{
+
+    /**
+     * Get the mail representation of the notification.
+     *
+     * @param  mixed  $notifiable
+     * @return \Illuminate\Notifications\Messages\MailMessage
+     */
+    public function toMail($notifiable)
+    {
+        return (new MailMessage)
+                ->line('You are receiving this email because we received a password reset request for your account.')
+                ->action('Reset Password', url(config('app.url').'/password/reset/'.$this->token).'?email='.urlencode($notifiable->email))
+                ->line('If you did not request a password reset, no further action is required.');
+    }
+
+}

+ 12 - 0
app/User.php

@@ -2,6 +2,7 @@
 
 namespace App;
 
+use App\Notifications\ResetPassword;
 use Illuminate\Notifications\Notifiable;
 use Illuminate\Contracts\Auth\MustVerifyEmail;
 use Illuminate\Foundation\Auth\User as Authenticatable;
@@ -37,4 +38,15 @@ class User extends Authenticatable
     protected $casts = [
         'email_verified_at' => 'datetime',
     ];
+
+    /**
+     * Send the password reset notification.
+     *
+     * @param  string  $token
+     * @return void
+     */
+    public function sendPasswordResetNotification($token)
+    {
+        $this->notify(new ResetPassword($token));
+    }
 }