Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Emokores's avatar

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']
	]

0 likes
9 replies
Sinnbeck's avatar

Please show some code. It sounds like your rules array is wrapped in an array or is missing keys.

Emokores's avatar

@Sinnbeck Another thing I did was that I added custom message in the return:


return [
    [
         //validation rules here
    ],
    [
        // custom validation messages here
    ]
]

Don't know if this is the right syntax.

Emokores's avatar

@Sinnbeck Do I have to use a new public function messages() {} to pass the custom error messages in the StorePatientRequest?

Please or to participate in this conversation.