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?
As of Laravel 5.7 you can pass an array of options to Auth::routes() . You can then disable the register routes with: Auth::routes(['register' => false]);
People can't login without an account, so just disable the register feature in config/fortify. php . The laravel/ui package is designed for Laravel 6 and 7 -- it can be installed with Laravel 8 too, but the "new thing" there is Jetstream for your authentication scaffolding.
The code
:
Auth::routes();
its a shorcut for this collection of routes:
// Authentication Routes... Route::get('login', 'Auth\LoginController@showLoginForm')->name('login'); Route::post('login', 'Auth\LoginController@login'); Route::post('logout', 'Auth\LoginController@logout')->name('logout'); // Registration Routes... Route::get('register', 'Auth\RegisterController@showRegistrationForm')->name('register'); Route::post('register', 'Auth\RegisterController@register'); // Password Reset Routes... Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request'); Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email'); Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset'); Route::post('password/reset', 'Auth\ResetPasswordController@reset');
So you can substitute the first with the list of routes and comment out any route you don't want in your application.
Edit for laravel version => 5.7
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', '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');
BTW you can also disable Password Reset
and Email Verification
routes:
Auth::routes(['reset' => false, 'verify' => false]);
Since Laravel 5.7, a new $options
parameter is introduced to the Auth::routes()
method; through which you can pass an array to control the generation of the required routes for user-authentication (valid entries can be chosen from the 'register'
, 'reset'
, or 'verify'
string literals).
Auth::routes(['register' => false]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With