Laravel study notes (15) retrieve your password via email

  1. Password generation controller
  2. Add Route
  3. Send e-mail page
  4. Notify Send e-mail use

Generating notify file

artisan make:notification findEmailNotify

Edit the message content in a file

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;

class findEmailNotify extends Notification
{
    use Queueable;

    protected $token;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct($token)
    {
        $this->token = $token;
    }

    /**
     * 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($notifiable)
    {
        return (new MailMessage)
                    ->subject('找回密码')    // 标题
                    ->line('点击链接找回密码')
                    ->action('重置密码', url(route('passwordEmailEdit', [$this->token])))
                    ->line('感谢您的使用');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

The controller sends a message

       \Notification::send($user, new findEmailNotify($user->email_token));

Here Insert Picture Description
You can modify the template HTML and Plain Text Templates notice issued by resource package. After running this command, the mail notification template was placed on the resources / views / vendor / notifications folder:

php artisan vendor:publish --tag=laravel-notifications
  1. Password change page
  2. Password Update
Published 40 original articles · won praise 0 · Views 777

Guess you like

Origin blog.csdn.net/qj4865/article/details/104212626