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

问题描述 投票:0回答:2
protected function rules()
{
    return (new FormRequest)->rules();
}

如上面的代码如何使用多个请求类?

php laravel validation laravel-livewire
2个回答
0
投票

从技术角度来说,您根本不应该在 Livewire 中使用表单请求。但是,由于您仅使用表单请求中的规则,因此您只需要一个

array_merge

protected function rules()
{
    return array_merge(
        (new FormRequest)->rules(),
        (new OtherRequest)->rules(),
    );
}

0
投票
protected function rules(){

    return array_merge(

        (new FormRequest)->rules(),

        (new OtherRequest)->rules(),

    );

}

如果您的规则中没有错误,那么这可以正常工作,但不能用于多种表单。在多个表单中,单击一个提交会将验证错误推送到另一个表单上。您可以在要用于验证的新方法上尝试此操作

公共函数 updateProfile(FormRequest, $request){

$data = $this->validateOnly($request->rules());




 Profile::create($data);

}

© www.soinside.com 2019 - 2024. All rights reserved.