I am trying to create an error message using a validator. Currently I got it working it using the following code.
$validator = Validator::make(request()->all() ,[
'banner' => 'max:2048',
], [
'banner.max' => 'The :attribute must be less than 2MB.',
]);
if ($validator->fails()) {
return redirect()
->back()
->withErrors($validator)
->withInput();
}
I don't need to redirect the user when the validation fails. So I have removed the redirect response however, doing so cause me to receive this error with my following code changes. I am not sure why only JSON response is received.
All Inertia requests must receive a valid Inertia response, however a plain JSON response was received
if ($validator->fails()) {
return $validator->errors()->all();
}