Is there any way to pass complex parameter (for example array of objects) to middleware in laravel? I know that I can pass strings via some kind of DSL but I need to pass some more complicated data to one of middlewares. Is this achievable? And if so, how?
There is example what I want to achieve
class Middleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next, array $modifiers = null)
{
foreach($modifiers as $name => $closure) {
$request->$name = $closure($request->name)
}
return $next($request);
}
}
And I want to pass
[
'param' => function($param) { return $param * 2; }
]
As $modifiers
parameter to Middleware, and that array will be different for different routes so passing by global context is no go.