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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:05:45  来源:igfitidea点击:

Laravel 5.7 Email Verification Routes

phplaravel

提问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.verifyroute 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\Registeredis emit. Laravel come whith a listener Illuminate\Auth\Listeners\SendEmailVerificationNotificationwhich is already registered in the App\Providers\EventServiceProvider.

在注册过程中,Illuminate\Auth\Events\Registered会发出一个事件。Laravel 带有一个Illuminate\Auth\Listeners\SendEmailVerificationNotification已经在App\Providers\EventServiceProvider.

After implementing the MustVerifyEmailinterface when the Registeredevent is emit the SendEmailVerificationNotificationlistener will check if the App\Userhave already use the Illuminate\Contracts\Auth\MustVerifyEmailtrait by checking if the user create is an instance of MustVerifyEmailif that is the case it will call the sendEmailVerificationNotificationmethod on the userwhich get the implementation of this method when it use the Illuminate\Auth\MustVerifytrait.

实现后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 sendEmailVerificationNotificationto emit a custom eventwhich can have a custom listener in which you will perform all the verification stuff and notify the userby 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 安装程序。