The following method works great:
Copy all the routes from /vendor/laravel/framework/src/Illuminate/Routing/Router.php and paste it into web.php and comment out or delete Auth::routes().
Then setup a conditional to enable and disable registration from .env. Duplicate the 503.blade.php file in views/errors and create a 403 forbidden or whatever you like.
Add ALLOW_USER_REGISTRATION= to .env and control user registration by setting its value to true or false.
Now you have full control of routes and Vendor files remain untouched.
web.php
//Auth::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...
if (env('ALLOW_USER_REGISTRATION', true))
{
Route::get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
Route::post('register', 'Auth\RegisterController@register');
}
else
{
Route::match(['get','post'], 'register', function () {
return view('errors.403');
})->name('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');
This is a combination of some previous answers notably Rafal G. and Daniel Centore.
routes.php
. To enable the authentication functions, all you do is addRoute::auth();
to the file. – miken32 May 26 '16 at 21:23Route::auth()
shortcut was advocated. – Martin Bean May 27 '16 at 8:17