0
votes

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

1
Why are they both named user_index?Jeremy Harris
They're not, admin is user_index user is User::user_index I've tried changing the name and I get the same issue :(bashleigh
Did you get this fixed? I have the same problemAdRock
I did yes. I kind of hacked it to be honest. I made an additional controller which did the condition for me so there was only one route. I can find it if you'd like? @AdRockbashleigh
That would be greatAdRock

1 Answers

0
votes

This is probably wrong but this is what I did to fix this particular issue with the above.

public function index() {

    return \Auth::user()->hasRole("trainer") ? \App::call("App\Http\Controllers\Trainer\UserController@index")
    : \App::call("App\Http\Controllers\User\UserController@index");
}