Categories: Development

Changing Laravel default login route

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.

 

 

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

2 years ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

2 years ago

FTP getting array of file details such as size using PHP

Using FTP and PHP to get an array of file details such as size and…

3 years ago

Creating Laravel form requests

Creating and using Laravel form requests to create cleaner code, separation and reusability for your…

3 years ago

Improving the default Laravel login and register views

Improving the default Laravel login and register views in such a simple manner but making…

3 years ago

Laravel validation for checking if value exists in the database

Laravel validation for checking if a field value exists in the database. The validation rule…

3 years ago