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

Ligonsker's avatar

Do they have a mistake in the following example from the docs?

From the Middleware page:

https://laravel.com/docs/9.x/middleware#middleware-parameters

They give example with a class called EnsureUserHasRole

Then they say:

Middleware parameters may be specified when defining the route by separating the middleware name and parameters with a :. Multiple parameters should be delimited by commas:

Route::put('/post/{id}', function ($id) {
    //
})->middleware('role:editor');

But shouldn't it be:

->middleware('EnsureUserHasRole:editor')
0 likes
2 replies
Ligonsker's avatar

@Sinnbeck ah yes! Forgot about the part where you register it in Kernel. Ty πŸ˜€πŸ˜ΆπŸ˜Ά

Please or to participate in this conversation.