Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eggplantSword's avatar

Change default login routes

I'm trying to create a landing page that is informational and there is a dialog that opens up where the admin can login, however it's not a login page only.

The default routes show up as /login which I don't want. I would like the landing page to have the route \info.

Right now I have the original setup web.php

Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
Route::post('login')->name('login.attempt')->uses('Auth\LoginController@login');

Route::group(['middleware' => 'auth'], function () {
    Route::resource('/', 'DashController');
    Route::get('/logout')->name('logout')->uses('Auth\LoginController@logout');

});

Authenticate middleware

protected function redirectTo($request)
    {
        if (! $request->expectsJson()) {
            return route('login');
        }
    }

How can I change it? I'm using Laravel 6x.

0 likes
15 replies
Snapey's avatar

You can post login data from a modal on your home page to the login controller.

The only problem is with the middleware that intercepts connection to a route that requires authentication.

As you note, it redirects to 'login' route.

I would create a page that is at the login route, has a copy of the login form, and is only used when someone tries to go to a back-end page without being logged in.

eggplantSword's avatar

@snapey this is a very simple page, the only thing I want to do is change the name that appears in the url from login to something else, I don't want to touch the functionality

Snapey's avatar

Don't confuse the route name 'login' and the route '/login'

you could attach the name 'login' to /

edit:

Looking at your routes;

Route::group(['middleware' => 'auth'], function () {
    Route::resource('/', 'DashController');
    Route::get('/logout')->name('logout')->uses('Auth\LoginController@logout');

});

you have placed the root folder / inside the auth middleware. This means you cannot show any home page content to any user that is not logged in. You should move this route outside of the auth middleware and create a different route for dashboard.

If you don't want to do this then you have to stick with directing users to a /login route as you have now.

eggplantSword's avatar

@snapey After I move the DashController outside the middleware how would I show the admin dash to the logged in user only?

MichalOravec's avatar

@msslgomez Just add some prefix for example user

Route::prefix('user')->group(['middleware' => 'auth'], function () {
    Route::resource('/', 'DashController');
    Route::get('/logout')->name('logout')->uses('Auth\LoginController@logout');
});

Route::get('/', 'HomeController@index');
eggplantSword's avatar

@michaloravec This gives me this error

Symfony\Component\Debug\Exception\FatalErrorException Illuminate\Routing\RouteFileRegistrar::register(): Failed opening required 'Array' (include_path='C:\xampp\php\PEAR')

MichalOravec's avatar

@msslgomez You have older version of laravel so

Route::group(['prefix' => 'user', 'middleware' => 'auth'], function () {
    Route::resource('/', 'DashController');
    Route::get('/logout')->name('logout')->uses('Auth\LoginController@logout');
});

Route::get('/', 'HomeController@index');
eggplantSword's avatar
eggplantSword
OP
Best Answer
Level 9

I removed the prefix and changed the DashController base route to /admin and made the changes in the middleware and Auth controllers and that did it. Thanks for the help.

Snapey's avatar

After I move the DashController outside the middleware how would I show the admin dash to the logged in user only?

I NEVER said move the dash controller outside the middleware

eggplantSword's avatar

@snapey Thats what I understood when you said this

you have placed the root folder / inside the auth middleware. This means you cannot show any home page content to any user that is not logged in. You should move this route outside of the auth middleware and create a different route for dashboard.

1 like
Snapey's avatar

You should move this route

ie the / route

outside of the auth middleware and create a different route for dashboard.

create a different route (protected, inside auth middleware) for the dashboard

eggplantSword's avatar

@snapey this is what I have currently, how can I fix it. Right now I have to login twice for it to redirect me to the admin dash

Route::post('login')->name('login.attempt')->uses('Auth\LoginController@login');

Route::resource('/', 'DashController');

Route::group(['middleware' => 'auth'], function () {
    Route::get('/admin', 'HomeController@index');
    Route::get('/logout')->name('logout')->uses('Auth\LoginController@logout');
});
rakeshkumar's avatar

For example, if you have an organization-enabled application with an Application Login URI set to https://myappdotcom/login, then the link sent in the email invitation that an end-user receives will be: https://myappdotcom/login?invitation={invitation_ticket_id}&organization={organization_id}&organization_name={organization_name}.

Thus, the route in your application must accept invitation and organization parameters through the query string. To start the invitation acceptance transaction, it should forward both parameters along with the end-user to your Auth0 /authorize endpoint.

Please or to participate in this conversation.