1

I tried this:

Route::get('/', 'PageController@getIndex');
Route::group(array('before' => 'auth'), function(){
    Route::controller('/',            'HomeController'); 
});

But it is always requiring login.

I want the PageController@getIndex to be called when visiting '/' when logged in, and HomeController (@getIndex) otherwise.

I know I could set up a redirect, but I'd like to just handle it all within routing.

1
  • Yeah I am not sure if this way is possible. You have two locations assigned to the same route location, and declare that you want auth before reaching that location. You could use nested views in the home page and require Auth::check() before the login view and else to the normal home page or something. Otherwise I don't know if you would be able to route 2 separate pages to the same location. Commented Jun 21, 2013 at 1:26

1 Answer 1

1

You need to setup your own auth filter

if(!Auth::check()){
    return Route::get('/', 'PageController@getIndex');
} else {
    Route::controller('/',            'HomeController'); 
}
Sign up to request clarification or add additional context in comments.

1 Comment

It's worth keeping in mind that this won't work if you use route caching in the later versions of Laravel (I believe 5.1 and up ship with that feature).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.