protected function rules()
{
return (new FormRequest)->rules();
}
如上面的代码如何使用多个请求类?
从技术角度来说,您根本不应该在 Livewire 中使用表单请求。但是,由于您仅使用表单请求中的规则,因此您只需要一个
array_merge
。
protected function rules()
{
return array_merge(
(new FormRequest)->rules(),
(new OtherRequest)->rules(),
);
}
protected function rules(){
return array_merge(
(new FormRequest)->rules(),
(new OtherRequest)->rules(),
);
}
如果您的规则中没有错误,那么这可以正常工作,但不能用于多种表单。在多个表单中,单击一个提交会将验证错误推送到另一个表单上。您可以在要用于验证的新方法上尝试此操作
公共函数 updateProfile(FormRequest, $request){
$data = $this->validateOnly($request->rules());
Profile::create($data);
}