Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

kfc's avatar
Level 1

laravel middleware resolving [Parameter #0 [ <required> $request ]]

i have this middleware

class CheckRole
{
    public function handle(Request $request, Closure $next, string $section, mixed $roles): mixed
    {
        $userRoles = $request->user()->getAllRoles();
        if ($userRoles['panel']['full_perm'] == 1 || (isset($userRoles[$section]['full_perm']) && $userRoles[$section]['full_perm'] == 1)) {

            return $next($request);
        }

        $storedRoles = [];

        foreach ($roles as $role) {
            if (in_array($role, $userRoles[$section] ?? [])) {
                $storedRoles[] = $role;
            }
        }

        if (array_diff($roles, $storedRoles)) {
            return redirect()->back()->withErrors('You do not have permission to preform this action');
        }

        return $next($request);
    }
}

and i have theese routes in web

Route::middleware('role:panel,full_perm')->prefix('users')->group(function () {
        Route::post('/edit/{id}/{username}', [UsersController::class, 'editPost'])->name('users.edit-index');
    });
    Route::middleware('role:perks,xp_edit')->prefix('xp')->group(function () {
        Route::post('/edit/{uid}', [XpController::class, 'editXp'])->name('xp.edit-xp');
    });

when i try to access

users/edit/8

the middleware works fine, but for the xp routes i get this error

Unresolvable dependency resolving [Parameter #0 [ <required> $request ]] in class Illuminate\Http\Client\Request

0 likes
3 replies
Snapey's avatar

share the error? you can share the error publicly via a link on the error page

JussiMannisto's avatar
Level 50

The error message talks about Illuminate\Http\Client\Request. Usually you'd be dealing with Illuminate\Http\Request. The $next call is probably trying to invoke a controller method that has type-hinted the wrong class in its arguments.

Check if you're importing the wrong Request class in your controller.

1 like

Please or to participate in this conversation.