Laravel 5.4 Disable Register Route

Solution 1:

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]);

Solution 2:

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]);

Solution 3:

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.

Solution 4:

This is deceptively easy! You just need to override two methods in your app/Http/Controllers/Auth/RegisterController.php Class. See below which will prevent the form from being displayed and most importantly block direct POST requests to your application for registrations..

/**
 * Show the application registration form.
 *
 * @return \Illuminate\Http\Response
 */
public function showRegistrationForm()
{
    return redirect('login');
}

/**
 * Handle a registration request for the application.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function register(Request $request)
{
    abort(404);
}