User模型
use Illuminate\Contracts\Auth\MustVerifyEmail;
class User extends Authenticatable implements MustVerifyEmail
{
……
}
路由
Auth::routes([
'login' => true, // 登录
'logout' => true, // 退出
'register' => true, // 注册
'reset' => true, // 重置密码
'confirm' => true, // 额外的密码确认
'verify' => true, // 邮箱认证
]);
在env文件种配置好邮箱服务器信息之后。
邮箱验证地址
/email/verify
默认为英文模板,汉化验证邮件内容:
{
"Verify Email Address":"验证邮箱",
"Please click the button below to verify your email address.":"请单击下面的按钮验证您的电子邮件地址。",
"If you did not create an account, no further action is required.":"如果未创建帐户,则无需执行进一步操作。",
}
其中
If you're having trouble clicking the "验证邮箱" button, copy and paste the URL below into your web browser:
部分无法用lang汉化,需要执行一下
php artisan vendor:publish --tag=laravel-notifications
这样就出现一个模板
/resources/views/vendor/notifications/email.blade.php
邮箱验证邮件的内容部分就在这里。
需要验证邮箱才能访问的路由加上中间件
->middleware('auth', 'verified')