inertia-laravel
inertia-laravel copied to clipboard
Send Custom Validation Error to Front
How can I return custom validation errors to the frontend from the server?
I've tried all these different ways but none work well, where $message is any ramdom string
throw ValidationException::withMessages([
'pop_objects' => $message
]);
$validator = Validator::make([], []); // Empty data and rules fields
$validator->errors()->add('pop_objects', $message);
throw new ValidationException($validator);
abort(500, $message);
return redirect('pop-helper/deliveries/create')>withErrors($validator)->withInput();
throw new Exception($message);
In my Vue file I get the event but I can't get the custom message itself which is the important part.
Inertia.on('invalid', (event) => {
console.log(`An invalid Inertia response was received.`)
console.log(event.detail.response)
event.preventDefault()
});
How can I do this?