如何在规则方法(Livewire)中使用多个请求类


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);

}