Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override default Auth routes in Laravel >= 5.4

I want to override /login route to /admin/login. In web.php I tried

//Auth::routes(); Route::get('login', ['as' => 'auth.login', 'uses' => 'App\Modules\Admin\Controllers\AdminUserController@loginAdminUser'])->name('login'); 

But it is still showing Laravel default login form. How can I do this?

like image 411
Kiren S Avatar asked Apr 05 '17 07:04

Kiren S


People also ask

How do I change my Auth route in Laravel?

When you call Auth::routes() , following routes will be registered. basically delete Auth::routes() in your route file or overwrite default Laravel auth routes in your route file. Any further help, you must to give more information about the thing you'd like to achieve.

How do I remove Auth route in Laravel?

Removing the routes Quite simply you just need to copy the routes you want to use into you routes/web. php file and ditch the rest. You'll also need to replace $this-> with Route:: . Quite simply, you can now remove Auth::route() from your routes file and just leave behind the authentication and password reset routes.

What is Auth :: Routes () in Laravel?

Auth::routes() is just a helper class that helps you generate all the routes required for user authentication. You can browse the code here https://github.com/laravel/framework/blob/5.3/src/Illuminate/Routing/Router.php instead.


2 Answers

For the googlers, here is a full list of routes that are getting generated by Auth::routes(); in Laravel >= 5.4

// Authentication Routes... Route::get('login', [   'as' => 'login',   'uses' => 'Auth\LoginController@showLoginForm' ]); Route::post('login', [   'as' => '',   'uses' => 'Auth\LoginController@login' ]); Route::post('logout', [   'as' => 'logout',   'uses' => 'Auth\LoginController@logout' ]);  // Password Reset Routes... Route::post('password/email', [   'as' => 'password.email',   'uses' => 'Auth\ForgotPasswordController@sendResetLinkEmail' ]); Route::get('password/reset', [   'as' => 'password.request',   'uses' => 'Auth\ForgotPasswordController@showLinkRequestForm' ]); Route::post('password/reset', [   'as' => 'password.update',   'uses' => 'Auth\ResetPasswordController@reset' ]); Route::get('password/reset/{token}', [   'as' => 'password.reset',   'uses' => 'Auth\ResetPasswordController@showResetForm' ]);  // Registration Routes... Route::get('register', [   'as' => 'register',   'uses' => 'Auth\RegisterController@showRegistrationForm' ]); Route::post('register', [   'as' => '',   'uses' => 'Auth\RegisterController@register' ]); 

php artisan route:list will return

+--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+ | Domain | Method   | URI                    | Name             | Action                                                                 | Middleware   | +--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+ |        | GET|HEAD | login                  | login            | App\Http\Controllers\Auth\LoginController@showLoginForm                | web,guest    | |        | POST     | login                  |                  | App\Http\Controllers\Auth\LoginController@login                        | web,guest    | |        | POST     | logout                 | logout           | App\Http\Controllers\Auth\LoginController@logout                       | web          | |        | POST     | password/email         | password.email   | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web,guest    | |        | GET|HEAD | password/reset         | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest    | |        | POST     | password/reset         | password.update  | App\Http\Controllers\Auth\ResetPasswordController@reset                | web,guest    | |        | GET|HEAD | password/reset/{token} | password.reset   | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest    | |        | GET|HEAD | register               | register         | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest    | |        | POST     | register               |                  | App\Http\Controllers\Auth\RegisterController@register                  | web,guest    | +--------+----------+------------------------+------------------+------------------------------------------------------------------------+--------------+ 
like image 105
Gordon Freeman Avatar answered Oct 03 '22 02:10

Gordon Freeman


You can also try this one.

// Replace admin with whatever prefix you need  Route::group(['prefix' => 'admin'], function () {      Auth::routes();  }); 

You can see list of routes by following command.

php artisan route:list

enter image description here

like image 45
Asim Shahzad Avatar answered Oct 03 '22 01:10

Asim Shahzad