Framework: Middleware of Laravel 5.3 Multiple parameters request problem

Created on 20 Jan 2017  路  2Comments  路  Source: laravel/framework

In this it is written that the parameters can be separated by commas.
https://laravel.com/docs/5.3/middleware#middleware-parameters
I am creating a new project in Laravel 5.3 .
Since 2 hours i am thinking about the problem that why my middleware with the parameters is not working.
And everywhere it is suggested that it should be separated by comma (,) . But none of the suggestion was helpful.
Now when i tried passing the parameters using a semicolon ( ; ) then my middleware was working properly.

Route::get('/sid/sam', function () { return 'Hello World from sam1'; })->middleware('role:Admin;Superadmin');

Thanks . May be this suggestion is helpful.
:-)

Most helpful comment

If you define the handle method like this:

public function handle($request, Closure $next, ...$args)

And you pass role:admin,superadmin to the kernel.

the output of $args in the middleware will be an array ['admin', 'superadmin'].

All 2 comments

@sammysri commas are intented to pass multiple parameters, not multiple values.

imagine the following scenario:

->middleware('role:Admin,staff:false')

that's how commas are supposed to work, if you need multiple values on role, you can use any separation you like, as admin|operation|guest as long you break then down on your middleware

If you define the handle method like this:

public function handle($request, Closure $next, ...$args)

And you pass role:admin,superadmin to the kernel.

the output of $args in the middleware will be an array ['admin', 'superadmin'].

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JamborJan picture JamborJan  路  3Comments

shopblocks picture shopblocks  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments

CupOfTea696 picture CupOfTea696  路  3Comments

felixsanz picture felixsanz  路  3Comments