I would like the route argument to be passed as a middleware argument, something like this
Route::get('foo/{id}', ['middleware' => 'bar:{id}', function(){
});
How to do this?
You can get it from the request variable:
Route::get('foo/{id}', ['middleware' => 'bar', function(){
});
public function handle($request, Closure $next) {
$id = $request->id;
}
The
bar:id
is used when you want to pass the string id
to the middleware.
If you set the middleware up in the controller's constructor, it's possible to pass dynamic middleware variables.
public function __construct()
{
$this->middleware('bar:'.request()->id);
}