Display errors in a division. Have it hidden until you need to use it.
How to prevent redirection when validating with a traditional HTTP request?
Hello,
I am using server-fetched partials to fetch some data. Before the fetching, I am using basic validation inside the controller: https://laravel.com/docs/10.x/validation#quick-writing-the-validation-logic
public function getServerFetchedPartial(Request $request)
{
$validated = $request->validate([
'input1' => 'required|unique:posts|max:255',
'input2' => 'required',
]);
// return the data
}
Now if it passes, everything works fine and I get the data to the place I want in the blade file. However when validation fails, it returns the entire failed message to the designated area in the blade file, as seen in the docs:
If validation fails during a traditional HTTP request, a redirect response to the previous URL will be generated
In my case it's a modal, and it simply puts the entire error page inside a little modal.
How can I somehow "catch" this redirection and send custom error?
you can manually run the validator and then act on the result
https://laravel.com/docs/10.x/validation#manually-creating-validators
Please or to participate in this conversation.