Laravel 5.7 电子邮件验证路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52576535/
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
Laravel 5.7 Email Verification Routes
提问by nasirkhan
On Laravel 5.7 Email verification feature added. But on my project i do not use the default route names and added a prefix for my own purpose. Now when i added following code to add the verify routes, it shows an error.
在 Laravel 5.7 上添加了电子邮件验证功能。但是在我的项目中,我不使用默认路由名称并为我自己的目的添加了前缀。现在,当我添加以下代码以添加验证路由时,它显示错误。
Auth::routes(['verify' => true]);
Auth::routes(['verify' => true]);
Error message shows that the verification.verify
route does not exists. Where can i update this route name in my project? Or is it the only way to use this feature is to follow the default Auth Route names?
错误消息显示verification.verify
路由不存在。我在哪里可以在我的项目中更新此路线名称?或者使用此功能的唯一方法是遵循默认的身份验证路由名称?
Project Source Code Is available at https://github.com/nasirkhan/laravel-starter/tree/l57
项目源代码可在https://github.com/nasirkhan/laravel-starter/tree/l57 获得
回答by tompec
Instead of using Auth::routes(['verify' => true]);
just use Auth::routes();
and manually add these routes:
而不是Auth::routes(['verify' => true]);
仅使用Auth::routes();
并手动添加这些路由:
Route::get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
Route::get('email/verify/{id}', 'Auth\VerificationController@verify')->name('verification.verify');
Route::get('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');
Then customise as you want :)
然后根据需要自定义:)
回答by Yves Kipondo
When you want to change the route throught which the verification process will be done you must change all the way the verification process work.
当您想要更改完成验证过程的路线时,您必须更改验证过程的所有工作方式。
Email verification notification process
邮件验证通知流程
During the registration process an event Illuminate\Auth\Events\Registered
is emit. Laravel come whith a listener Illuminate\Auth\Listeners\SendEmailVerificationNotification
which is already registered in the App\Providers\EventServiceProvider
.
在注册过程中,Illuminate\Auth\Events\Registered
会发出一个事件。Laravel 带有一个Illuminate\Auth\Listeners\SendEmailVerificationNotification
已经在App\Providers\EventServiceProvider
.
After implementing the MustVerifyEmail
interface when the Registered
event is emit the SendEmailVerificationNotification
listener will check if the App\User
have already use the Illuminate\Contracts\Auth\MustVerifyEmail
trait by checking if the user create is an instance of MustVerifyEmail
if that is the case it will call the sendEmailVerificationNotification
method on the user
which get the implementation of this method when it use the Illuminate\Auth\MustVerify
trait.
实现后MustVerifyEmail
的界面,当Registered
事件发出SendEmailVerificationNotification
监听器会检查是否App\User
已经使用Illuminate\Contracts\Auth\MustVerifyEmail
通过检查用户创建的实例特征MustVerifyEmail
,如果是这样的话它会调用sendEmailVerificationNotification
上的方法user
,其得到这个方法时执行它使用Illuminate\Auth\MustVerify
特征。
Customization of the verification route
验证路径的自定义
To change the behavior of the verification process you can customize the sendEmailVerificationNotification
to emit a custom event
which can have a custom listener in which you will perform all the verification stuff and notify the user
by email in which you will send the custom route through which the verification process will be done
要更改验证过程的行为,您可以自定义sendEmailVerificationNotification
发出自event
定义侦听器,您将在其中执行所有验证内容并user
通过电子邮件通知您将发送验证过程将通过的自定义路由完成
回答by Leonardo
In my case, I had the same issue and I was receiving the message
就我而言,我遇到了同样的问题,并且收到了消息
InvalidArgumentException
Attribute [auth] does not exist.
at vendor/laravel/framework/src/Illuminate/Routing/RouteRegistrar.php:92
I've solved it updating my composer executable file and laravel local files.
我已经解决了它更新我的 Composer 可执行文件和 Laravel 本地文件的问题。
composer global self-update
composer update
It seems that my composer executable was using and old version of laravel installer.
似乎我的作曲家可执行文件正在使用旧版本的 laravel 安装程序。