I have the following naming conventions for input fields.
course_details[0][d_Total_Score]
course_details[1][d_Total_Score]
course_details[2][d_Total_Score]
Now I want to validate these fields with some rules. The following is the code I tried.
$validatedData = $request->validate([
'course_details.0.d_Total_Score' => 'required',
'course_details.1.d_Total_Score' => 'required',
'course_details.2.d_Total_Score' => 'required'
]);
I have taken reference from here
But this doesn't seem to be working.
HTML CODE:
<input placeholder="SAT score " class="form-control form-control-sm valid" id="d_Score_Sub_Category_SAT" name="course_details[0][d_Total_Score]" value="" aria-invalid="false" type="text">
RESOLVED: As d3jn said, the validations should not override anywhere.
corse_detailswith one rule:'course_details.*.d_Total_Score' => 'required'. More about it here. Also provide code of where are you using this rules - inFormRequestclass? UsingValidator? Are there any exceptions? We need more info.dd($request->input('course_details'))when you send your requests. I assume "this doesn't seem to be working" means you are not getting any errors even when not specifyingd_Total_Score. Or is it the opposite and you are always getting validation errors?dd($request->input('course_details'))showed there might be other input with thename="course_details[d_Total_Score]"somewhere after your original inputs and it's overriding the value that is sent with the request.