I did the laravel command for authentication system , php artisan make:auth it made the authentication system for my app and almost everything is working.

Now when i use the forgot password and it sends me a token to my mail id , i see that the template contains laravel and some other things that i might wanna edit or ommit, to be precise , i want my custom template to be used there.

我查看了控制器及其源文件,但找不到在邮件中显示html的模板或代码.

How do i do it ?

我该如何改变它?

This is the default template that comes from laravel to the mail. enter image description here

推荐答案

Just a heads up: In addition to the previous answer, there are additional steps if you want to modify the notification lines like You are receiving this..., etc. Below is a step-by-step guide.

你需要在User型号上使用override the default sendPasswordResetNotification方法.

Why? Because the lines are pulled from Illuminate\Auth\Notifications\ResetPassword.php. Modifying it in the core will mean your changes are lost during an update of Laravel.

为此,请将以下内容添加到User型号中.

use App\Notifications\PasswordReset; // Or the location that you store your notifications (this is default).

/**
 * Send the password reset notification.
 *
 * @param  string  $token
 * @return void
 */
public function sendPasswordResetNotification($token)
{
    $this->notify(new PasswordReset($token));
}

Lastly, create that notification:

php artisan make:notification PasswordReset

以及本通知内容的示例:

/**
 * The password reset token.
 *
 * @var string
 */
public $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'];
}

/**
 * Build 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.') // Here are the lines you can safely override
        ->action('Reset Password', url('password/reset', $this->token))
        ->line('If you did not request a password reset, no further action is required.');
}

Laravel相关问答推荐

如何返回Blade Laravel 中的按钮?

如何获取多态多对多关系子查询的自动 id 列名?

如何在 laravel 中为另一个用户 session()->forget('cart')?

基于值laravel提交表单后如何返回特定页面

Laravel 6 Passport 在错误的凭证上返回 400 Bad request

如何通过一个 laravel 安装处理子域

Laravel 4:验证前修剪输入的最佳实践

带有 Laravel Passport 的 SSO

路由模型绑定不起作用

Twilio 查找 API 不起作用?

如何在没有 Eloquent 的情况下创建 Laravel 模型?

WhereNotExists Laravel Eloquent

Laravel - 更新时禁用更新时间

如何运行artisan命令计划:在托管服务器上运行? (Laravel )

如何在 laravel 4 中删除文件

Laravel 验证存在于不存在的地方

在哪里放置 Blade::extend

如何在 Laravel 5 中验证 RESTful API?

Laravel如何仅响应没有正文消息的204代码状态

laravel中的动态网址?