chimit's avatar

Multiple middleware parameters in Lumen

From the Lumen documentation:

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:

But I can't make it work:

Routes:

$app->post('/files', ['middleware' => 'auth:write,manage', 'uses' => 'App\Http\Controllers\FileController@upload']);

Auth middleware:

public function handle($request, Closure $next, $permissions = null)
{
    var_dump($permissions);

It returns me only the first parameter: string 'write' (length=5). Is it a bug or my mistake?

0 likes
1 reply
chimit's avatar

Oops, I realized my mistake. I have to add a new argument to the handle function. But in my case it's hard to say how many parameters I will have. So I need an array. I tried to separate parameters with a pipe |, but it doesn't work. So the best way I see is to use a dot:

$app->post('/files', ['middleware' => 'auth:write.manage', 'uses' => 'App\Http\Controllers\FileController@upload']);

Is this logic correct?

Please or to participate in this conversation.