Let's say I have a route pointing to middleware;
Route::get("/user/{id}", ['middleware' => 'auth', function ($id) {
}]);
我的中间件代码如下:
public function handle($request, Closure $next)
{
return $next($request);
}
如果我想在中间件中使用$id
,我该怎么做?
Let's say I have a route pointing to middleware;
Route::get("/user/{id}", ['middleware' => 'auth', function ($id) {
}]);
我的中间件代码如下:
public function handle($request, Closure $next)
{
return $next($request);
}
如果我想在中间件中使用$id
,我该怎么做?
You can use one of the following method to access the route parameter in a middleware:
First Method个
$request->route()->parameters();
此方法将返回所有参数的array.
Second Method
$request->route('parameter_name');
Here parameter_name
refers to what you called the parameter in the route.