How to change the default Laravel authentication routes such as Login and register to your own custom-defined routes.
This example will change the default login route from /login
to /signin
.
I am using Laravel UI which comes with embedded authentication routes. These are called with Auth::routes();
in the routes/web.php
file.
The best way to create your own custom route for login is to disable the default Laravel UI route
Auth::routes(['login' => false]);
Then define your own
Route::get('signin', 'App\Http\Controllers\Auth\LoginController@showLoginForm'); Route::post('signin', 'App\Http\Controllers\Auth\LoginController@login')->name('login');
Use the source as a template for controller and functions, by keeping the route named as login it will automatically be this custom route whenever a redirect to “login” occurs.
Now to change /register
to /create
Auth::routes(['login' => false, 'register' => false]); Route::get('create', 'App\Http\Controllers\Auth\RegisterController@showRegistrationForm'); Route::post('create', 'App\Http\Controllers\Auth\RegisterController@register')->name('register');
Make sure to run php artisan route:cache
after editing routes.