In my Laravel application im trying to validate the body of my request, but one specific situation throws a ValidationException.
My code looks like this:
public function updateData(Request $request){
try {
$validatedData = $request->validate([
'ids' => ['required', 'array'],
'ids.*' => 'integer'
]);
catch (ValidationException $th) {
return response()->json($this->createFailedResult($th->errors()));
}
}
The Data I pass looks like this:
No Exception:
{
ids: [1]
}
With Exception:
{
ids: []
}
Thats the Ecception:
[ids] => Array ( [0] => The ids field is required. ) )
I've read about exchanging "required" with "present", but i dont want empty strings to be ignored by the validation.
Thanks for your help!