Sam Pettersson
Sam Pettersson

Reputation: 3217

Multiple routes which uses the same uri

Is it possible in laravel routes to set multiple routes for the same uri? example: /home based on if a user is guest or logged in or so on?

I tried some using filters but thoose just redirect around creating a loop, how would i if it's possible write my filters to support this?

I need this because the login page and logged in page should be at the same uri.

Upvotes: 0

Views: 151

Answers (2)

Cody Covey
Cody Covey

Reputation: 1060

I would do this in the controller.

Route::get('login', 'AwesomeController@login');

then in your controller

public function login()
{
    if ($user = Auth::user()) {
        return View::make('view', [ 'user' => $user ]);
    }

    return View::make('notLoggedInView');
}

Upvotes: 0

JackPoint
JackPoint

Reputation: 4111

Dont know it there is a better solution, but I think you can do this:

if(Auth::check()){
   Route::get('route-for-loggedin');
} else {
   Route::get('route-for-NOT-loggedin');
}

Upvotes: 1

Related Questions