Laravel 5.4 禁用注册路由

2021-12-18 00:00:00 php laravel laravel-5.4

我正在尝试禁用在 Laravel 5.4 中运行的应用程序上的注册路由.

I am trying to disable the register route on my application which is running in Laravel 5.4.

在我的路由文件中,我只有

In my routes file, I have only the

Auth::routes();

有什么办法可以禁用注册路由吗?

Is there any way to disable the register routes?

推荐答案

code:

Auth::routes();

这是这组路线的捷径:

// Authentication Routes...
Route::get('login', 'AuthLoginController@showLoginForm')->name('login');
Route::post('login', 'AuthLoginController@login');
Route::post('logout', 'AuthLoginController@logout')->name('logout');

// Registration Routes...
Route::get('register', 'AuthRegisterController@showRegistrationForm')->name('register');
Route::post('register', 'AuthRegisterController@register');

// Password Reset Routes...
Route::get('password/reset', 'AuthForgotPasswordController@showLinkRequestForm')->name('password.request');
Route::post('password/email', 'AuthForgotPasswordController@sendResetLinkEmail')->name('password.email');
Route::get('password/reset/{token}', 'AuthResetPasswordController@showResetForm')->name('password.reset');
Route::post('password/reset', 'AuthResetPasswordController@reset');

因此,您可以用路由列表替换第一个,并注释掉您的应用程序中不需要的任何路由.

So you can substitute the first with the list of routes and comment out any route you don't want in your application.

编辑 laravel 版本 =>5.7

在较新的版本中,您可以向 Auth::routes() 函数调用添加一个参数以禁用注册路由:

In newer versions you can add a parameter to the Auth::routes() function call to disable the register routes:

Auth::routes(['register' => false]);

添加了电子邮件验证路径:

The email verification routes were added:

Route::get('email/verify', 'AuthVerificationController@show')->name('verification.notice');
Route::get('email/verify/{id}', 'AuthVerificationController@verify')->name('verification.verify');
Route::get('email/resend', 'AuthVerificationController@resend')->name('verification.resend');

顺便说一句,您还可以禁用 Password ResetEmail Verification 路由:

BTW you can also disable Password Reset and Email Verification routes:

Auth::routes(['reset' => false, 'verify' => false]);

相关文章