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

Early September spring shots

Some early September spring shots from a bushwalk, It is still too early for wildflowers.

3 years ago

Cloning an NVMe to SK Hynix Platinum P41 NVMe

I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…

3 years ago

Using Laravel’s deleteDirectory to delete folders and their contents

If you ever needed a simple solution in Laravel to delete an entire directory and…

3 years ago

How to allow only 1 user to register in a Laravel application

How to enforce only one user to register or be registered in a Laravel web…

3 years ago