1
votes

Hey there fellow developers,

I am struggling a little bit with laravel routing. I just build the login code and logging in seems to work properly. However when I am redirected to "/" I end up getting a redirect loop.

When guest the default url = "/" and when authenticated the default url also = "/", so my guess something is not working the way I intend it there.

The relevant routes code is as follows:

Route::group(["before" => "guest"], function() {
    Route::any("/", [
        "as"    => "home/splash",
        "uses"  => "HomeController@showSplash"
    ]);
});

Route::group(["before" => "auth"], function() {
    Route::any("/", [
        "as"    => "home/dashboard",
        "uses"  => "HomeController@showDashboard"
    ]);
});

When I remove the before auth group it loads the splash page. When I change the name of before "auth" to "auth5" for instance, it loads the dashboard.. but auth5 is not programmed in, in any place in my code.. so either I am totally obvlivious to how these route groups are supposed to work or I am doing something stupidly wrong :p

Last but not least, my auth filter also redirects to "/"

Regards,

Pwnball

Update =>

/* GUESTS GROUP */
Route::group(["before" => "guest"], function() {

Route::any("/splash", [
    "as"    => "home/splash",
    "uses"  => "HomeController@showSplash"
]);


/* AUTHENTICATED USERS GROUP */
Route::group(['before' => 'auth'], function() {

Route::any("/dashboard", [
    "as"    => "home/dashboard",
    "uses"  => "HomeController@showDashboard"
]);

This works.. but now my website cannot be reached as "/" anymore. This is frustrating for obvious reasons..

When I add this route in the before => guest group:

Route::any("/", [
    "as"    => "home/home",
    "uses"  => "HomeController@showSplash"
]);

It goes right back into redirect loops. My filter looks as follows:

Route::filter('auth', function()
{
    if (Auth::guest())
    {
        if (Request::ajax())
        {
            return Response::make('Unauthorized', 401);
        }
        else
        {
            return Redirect::guest('/splash');
        }
    }
});

Route::filter('guest', function()
{
    if (Auth::check()) return Redirect::to('/');
});

I must really be missing something obvious :)

2
You probably have to modify your filters.php as well. - peter.babic
@delmadord well as I said, my auth filter already redirects to "/" :p - Pwnball
can you post your auth & guest filter code - Laurence
small update, I think its now going to my route file -> it sees "before" => "auth", runs the filter code that redirects to "/", where he goes back it sees the "before" => "auth" again, runs the filter code again.. etc think that is causing the loop :) - Pwnball
Just make auth filter redirec to login page instead of / - peter.babic

2 Answers

0
votes

Just make auth filter redirect to login page instead of '/'

0
votes

Long story short, those filters are nothing but annoying, when doing http requests you can either take the route.. or you will get a 404. Simple as that!

if (Auth::guest()) {
    << Routes for guests go here >>
} else {
    << Routes when logged in go here >>
}

End of story!

Thanks for the assistance guys!