我有一個格式的請求
array:2 [▼
"_token" => "Lqn3XPvbdhLC8iqs461xSrGYPmxmSv4PGCqH7LJQ"
"branch" => array:16 [▼
"customer_company_id" => "5"
"is_main" => "true"
]
]
我需要通過以下方式驗證表單:
- 如果 customer_company_id 存在
name則不需要 - 如果 customer_company_id 不存在
name則為必填項
我的 FormRequest 看起來像
public function rules(): array
{
return [
'branch' => [
'is_main' => [
'required',
'boolean'
],
'customer_company_id' => [
'required_without:branch.name'
],
],
];
}
它引發以下錯誤
Method Illuminate\Validation\Validator::validateRequiredWithout:branch.name does not exist
uj5u.com熱心網友回復:
這個怎么樣?
return [
'branch.name' => 'required_without:branch.customer_company_id',
'branch.is_main' => 'required|boolean',
'branch.customer_company_id' => 'required_without:branch.name',
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/331013.html
