You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the moment as far as I know it's possible to use two kinds of middleware notation:
To pass string alias. optionally you can pass also the params: ->middleware('middleware1:param1,param2'); . Also it's possible to pass an array of such strings for several middlewares.
Alternatively it's possible to use full class name via ::class: ->middleware(EnsureTokenIsValid::class); . Or you can pass an array of such classes for several middlewares.
The second approach is more convenient I think as it has better support from the IDE side.
But there is a problem here with params. If you want to pass the param with such kind of notation, you have to use some workaround like this: ->middleware(EnsureTokenIsValid::class . ':param1'); Another one downside is that it's possible to pass only string as a param.
I think it would be more convenient to use something like key-value array to pass such params. E.g.: ->middleware([EnsureTokenIsValid::class => $param, SomeOtherMiddleware::class => $param]);
or even this way with several params: ->middleware([EnsureTokenIsValid::class => [$param1, $param2], SomeOtherMiddleware::class => [$param1, $param2]]);
I can make a PR for this feature but would like to ensure it fits by Laravel design.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
On the moment as far as I know it's possible to use two kinds of middleware notation:
->middleware('middleware1:param1,param2');
. Also it's possible to pass an array of such strings for several middlewares.->middleware(EnsureTokenIsValid::class);
. Or you can pass an array of such classes for several middlewares.The second approach is more convenient I think as it has better support from the IDE side.
But there is a problem here with params. If you want to pass the param with such kind of notation, you have to use some workaround like this:
->middleware(EnsureTokenIsValid::class . ':param1');
Another one downside is that it's possible to pass only string as a param.I think it would be more convenient to use something like key-value array to pass such params. E.g.:
->middleware([EnsureTokenIsValid::class => $param, SomeOtherMiddleware::class => $param]);
or even this way with several params:
->middleware([EnsureTokenIsValid::class => [$param1, $param2], SomeOtherMiddleware::class => [$param1, $param2]]);
I can make a PR for this feature but would like to ensure it fits by Laravel design.
Beta Was this translation helpful? Give feedback.
All reactions