Please show some code. It sounds like your rules array is wrapped in an array or is missing keys.
Cannot see the field having the wrong data - Inertia with React
I have a form that submits patient data. But, when I dump the data dd($request), everything seems okay. However, the validation message in the console shows the error: The 0 field is required. I don't know what the problem is. All the frontend fields match the validated field names in the StorePatientRequest.
This is what I have when I dd():
[▼
"name" => "Phillip Humphrey"
"email" => "[email protected]"
"gender" => "M"
"age_type" => "yo"
"age" => "60"
"dob" => "2007-12-25"
"date_recorded" => null
"mobile_number" => "+1 (368) 179-9545"
"mobile_number_2" => "+1 (332) 836-1931"
"occupation" => "retired"
"address" => "Et sit ducimus har"
"nok_id" => "2"
"relation_to_next_of_kin" => "1"
"other_relation_to_next_of_kin" => null
"referral_point" => "1"
"referral_point_details" => null
"other_referral_point_details" => null
"insurance_scheme" => "0"
"insurance_id" => null
"insurance_number" => null
]
The null fields are validated with either the required_if:field,value or nullable.
This is what I have in the StorePatientRequest:
[
'name' => ['required', 'string'],
'email' => ['email', 'nullable', 'unique:patients,email'],
'gender' => ['required'],
'age_type' => ['required'],
'age' => ['required, numeric'],
'dob' => ['required'],
'address' => ['required'],
'occupation' => ['required'],
'mobile_number' => ['required'],
'nok_id' => ['required'],
'relation_to_nok' => ['required'],
'other_relation_to_nok' => ['nullable', 'required_if:relation_to_nok,5'],
'referral_point' => ['required'],
'referral_point_details' => ['required_if:referral_point,2,4,5', 'nullable'],
'other_referral_point_details' => ['required_if:referral_point,2,4,5', 'nullable'],
'insurance_scheme' => ['required'],
'insurance_id' => ['required_if:insurance_scheme,1', 'nullable'],
'insurance_number' => ['required_if:insurance_scheme,1', 'nullable'],
'deceased' => ['required'],
'deceased_date' => ['required_if:deceased,1', 'nullable'],
'date_recorded' => ['nullable', 'date']
]
@Emokores can you show the Controller action and all of the StorePatientRequest class?
Don't know if this is the right syntax.
EDIT: it is not; there is a messages method on the FormRequest class for the validation messages
https://laravel.com/docs/9.x/validation#customizing-the-error-messages
Please or to participate in this conversation.