Support the ongoing development of Laravel.io →
Authentication Requests

Hi, I want to use request name ('/') when the user is authorized and for the guests. I want to use localhost/ to route user to admin panel when he is authorized, and when he is guest I want to route him to localhost/ too (in this case will be home page for all users). So, I tried to use it into my routes.php:

Route::group(['middleware' => 'guest'], function()
{
    Route::get('/', ['as' => 'auth.login', 'uses' => 'Auth\AuthController@formLogin']);
    Route::post('login', ['as' => 'auth.login.post', 'uses' => 'Auth\AuthController@login']);
});

Route::group(['middleware' => 'auth'], function()
{
    Route::get('/', function() {
        view('welcome');
    });
    Route::get('logout', ['as' => 'auth.logout', 'uses' => 'Auth\AuthController@logout']);
});

But when I make the command php artisan route:list I see that:

+--------+----------+--------+-----------------+-------------------
| Method   | URI    | Name            | Middleware  |
+--------+----------+--------+-----------------+---------------------
|GET|HEAD | /      |                 |  auth           |
|POST     | login  | auth.login.post |  guest,guest |
|GET|HEAD | logout | auth.logout     | auth,guest    |
+--------+----------+--------+-----------------+---------------------

middleware 'auth' overrides middleware 'guest' for the '/' request. This is a very big problem for me.

In Laravel 4.2 this could be done through the filters 'before' => 'guest' and 'before' => 'auth'.

How can I filter the same requests ('/') throw middleware? Thanks in advance for any help!

Last updated 3 years ago.
0

I think you need to use if statement to create that route.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

nvasiliev nvasiliev Joined 19 Jul 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.