在 Laravel 中自定义密码重置邮件视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30498685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Customizing password reset mail View in Laravel
提问by Asami
How can I change what appears in the password reset email in laravel? Like addressing the user with his name and show the password reset link etc. Where is that email view located?
如何更改 Laravel 中密码重置电子邮件中显示的内容?就像用他的名字称呼用户并显示密码重置链接等。电子邮件视图在哪里?
采纳答案by Ali Malik
Yes you can change the email template, which is located at
是的,您可以更改电子邮件模板,该模板位于
resources/views/emails/password.blade.php.
For customization pass an instance of User model to this view and echo out user name there like:
对于自定义,将 User 模型的实例传递到此视图并在那里回显用户名,例如:
Hello, {{$user->username}}
//And Body of Reset link goes here
Update for laravel 5.3+
Laravel 5.3+ 更新
In updated laravel versions the code structure is revamped. Password reset mail is now at vendor/laravel/framework/src/Illuminate/Auth/Notifications/ResetPassword.php
在更新的 Laravel 版本中,代码结构得到了改进。密码重置邮件现在位于vendor/laravel/framework/src/Illuminate/Auth/Notifications/ResetPassword.php
and its corresponding template is at: resources/views/vendor/notifications/email.blade.php
其对应的模板在: resources/views/vendor/notifications/email.blade.php
So in order to customize it, you may need to:
因此,为了自定义它,您可能需要:
- Copy it to somewhere in your app's directory.
- Set the proper namespace to refer to it.
- Add a new method to User class & reference it to newly copied class
- Customize.
- 将其复制到应用程序目录中的某个位置。
- 设置正确的命名空间以引用它。
- 向 User 类添加新方法并将其引用到新复制的类
- 定制。
回答by Arno van Oordt
In Laravel 5.3 they changed the entire password reset code, so the given answer doesn't work anymore.
在 Laravel 5.3 中,他们更改了整个密码重置代码,因此给出的答案不再有效。
If you want to change the basic texts you should copy vendor/laravel/framework/src/Illuminate/Auth/Notifications/ResetPassword.php to some place in your own app (e.g. app/Notifications/ResetPassword.php), set the correct namespace and alter the texts as you wish. (don't alter the original ResetPassword.php since it's bad practice to alter files in the vendor folder!)
如果你想改变基本文本,你应该将 vendor/laravel/framework/src/Illuminate/Auth/Notifications/ResetPassword.php 复制到你自己的应用程序中的某个地方(例如 app/Notifications/ResetPassword.php),设置正确的命名空间并根据需要更改文本。(不要更改原始的 ResetPassword.php,因为更改供应商文件夹中的文件是不好的做法!)
Then add a sendPasswordResetNotification
method to the User class and make sure to reference to the appropriate ResetPassword class:
然后sendPasswordResetNotification
向 User 类添加一个方法,并确保引用适当的 ResetPassword 类:
use App\Notifications\ResetPassword;
...
public function sendPasswordResetNotification($token) {
$this->notify(new ResetPassword($token));
}
If you want to change the rest of the mail template (which is used for all other mails as well) do the following:
如果要更改邮件模板的其余部分(也用于所有其他邮件),请执行以下操作:
Run php artisan vendor:publish
跑 php artisan vendor:publish
This will copy some blades from the vendor folder to the resources/views/vendor The resources/views/vendor/notifications/email.blade.php is the one you want to change.
这会将一些刀片从供应商文件夹复制到 resources/views/vendor resources/views/vendor/notifications/email.blade.php 是您要更改的那个。
Hope this helps for people who got stuck in Laravel 5.3
希望这对陷入 Laravel 5.3 的人有所帮助