Laravel 5.4 Disable Register Route
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]);
You could try this.
Route::match(['get', 'post'], 'register', function(){
return redirect('/');
});
Add those routes just below the Auth::routes()
to override the default registration routes. Any request to the /register
route will redirect to the baseUrl.