如何将所有\Lightning\Http\Request$Request数据设置为FormRequest对象,以便在LARAVEL的控制器中使用
我已经创建了用于数据验证的表单请求, 我还为request modify创建了中间件,该中间件通过从query参数获取值,在如何将所有\Lightning\Http\Request$Request数据设置为FormRequest对象,以便在LARAVEL的控制器中使用,laravel,forms,middleware,Laravel,Forms,Middleware,我已经创建了用于数据验证的表单请求, 我还为request modify创建了中间件,该中间件通过从query参数获取值,在\lighting\Http\request对象中添加一个键 我想要\illustration\Http\Request对象数据,该数据由中间件修改后与表单请求一起附加,以便我可以使用$Request对象在控制器中进一步使用 我已将中间件代码写入baseformrequest(自定义类),并将该方法调用到我的formrequest中 中间件代码: public functi
\lighting\Http\request
对象中添加一个键
我想要\illustration\Http\Request
对象数据,该数据由中间件修改后与表单请求一起附加,以便我可以使用$Request对象在控制器中进一步使用
我已将中间件代码写入baseformrequest(自定义类)
,并将该方法调用到我的formrequest
中
中间件代码:
public function handle($request, Closure $next)
{
$requested_method = $request->route()->getActionMethod();
$required_with = [];
if($requested_method == 'show'){
if (!is_null($request->get('_with'))) {
$required_with = explode(',', $request->get('_with'));
}
}
$request->with = $request->get('_with');
return $next($request);
}
我希望所有修改的请求对象都可以在我的表单请求对象中访问,但我无法在我的Laravel控制器中访问您可以像这样向请求对象添加自定义属性
$request->attributes->add(['with' => $required_with])
然后您可以使用
$request->get('with');
请向我们展示您迄今为止在代码方面所做的工作。请共享您的中间件代码,并向社区展示您所做的工作