Chỉ cần một người đứng đầu lên: Ngoài các câu trả lời trước, có những bước bổ sung nếu bạn muốn thay đổi các dòng thông báo như You are receiving this...
, vv Dưới đây là một hướng dẫn từng bước.
Bạn cần phải override the defaultsendPasswordResetNotification
phương pháp trên mô hình User
của mình.
Tại sao? Bởi vì các đường được kéo từ Illuminate\Auth\Notifications\ResetPassword.php
. Sửa đổi nó trong lõi sẽ có nghĩa là những thay đổi của bạn bị mất trong quá trình cập nhật Laravel.
Để thực hiện việc này, hãy thêm thông tin sau vào mẫu User
của bạn.
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));
}
Cuối cùng, create that notification:
php artisan make:notification PasswordReset
Và ví dụ về nội dung của thông báo này:
/**
* 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.');
}
Email mẫu sẽ được bên trong nguồn/views/vendor/thư mục thông báo. – KCP
Tôi nghĩ câu trả lời hoàn chỉnh là https://stackoverflow.com/a/41401524/2144424 – jpussacq