I am using form request validation and allow for vehicles to be created in the form. Each vehicle has a ref which can be A, B, C, or D. However, in each form request there must always be a single ref: “A”. There can be any amount of the others.
I am not in control of the form. The requests come through an API.
My rules array currently contains:
'form.vehicles' => 'required',
'form.vehicles.*.ref' => 'required|in:A,B,C,D
Currently I am using the following code:
if (! in_array('A', $this->input('form.vehicles.*.ref'))) {
throw new HttpResponseException(response()->json(['MessageString' => 'Vehicle ref A is required'], 422));
This however means the messageBag is unable to be sent in the response for other validation issues.
Charlie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.