Middleware paramaters

- 1 answer

Ad

From the docs I can see that to pass a parameter editor to a middleware role you write

Route::put('post/{id}', ['middleware' => 'role:editor', function ($id) {
    ...
}]);

And to use the parameter in the middleware, you simply pass the parameter into the handle function

public function handle($request, Closure $next, $role)
{
    ...
}

My question is, where is this editor parameter coming from? I can only see the id in the URL string being passed about.

Ad

Answer

Ad

The $role variable within the handle parameters will contain the variable passed in after role:

so role:editor will return "editor"

Ad
source: stackoverflow.com
Ad