jeudi 28 juillet 2016

Laravel, same URI, different route name, different middleware causes over loop

In laravel I've simply done this:

Route::group(["middleware"    =>    "admin"], function() {

    Route::get("/", "UserController@index")->name("user_index");

});


Route::group(["middleware"    =>    "user", "as"    =>    "User::"], function() {

    Route::get("/", "DocumentController@index")->name("user_index");

});

The problem is when I am logged in as my Admin auth middleware, when going to "/" my browser returns too many redirects and stops. I'm guessing because the second route is removing this as when I print out php artisan route:list there is only one result for "/" and that's with the user middle's parameters so it's defo overriding the previous route.

What I don't understand is why would it do this is both have a separate middleware?

Both middlewares are extremely simple. Below is my admin

public function handle($request, Closure $next)
{

    if ( Auth::check() && Auth::user()->hasRole("customer_service") )
    {
        return $next($request);
    }

    return redirect("/");
}

And my user's middleware is exactly alike except the role is different



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire