Specify redirect? #88
Replies: 3 comments 1 reply
-
Just a heads up for anyone looking for a similar solution, this is how I'm currently working around the problem: try {
$data = IncomingData::from($request);
...
} catch (ValidationException $e) {
return redirect(route('process.start'))->withErrors($e->validator)->withInput();
} |
Beta Was this translation helpful? Give feedback.
-
Hi @danives, This isn't supported at the moment, I'm thinking it wouldn't be too difficult to support. But I don't have the time at the moment to implement such feature. I'm always open for a tested PR that adds this functionality! |
Beta Was this translation helpful? Give feedback.
-
This is supported by default in v2: https://spatie.be/docs/laravel-data/v2/as-a-data-transfer-object/request-to-data-object#content-overwriting-other-validation-functionality |
Beta Was this translation helpful? Give feedback.
-
Hey,
The standard Form Request classes within Laravel have the ability to specify a redirect location: https://laravel.com/docs/8.x/validation#customizing-the-redirect-location
Currently I'm using the Data class to handle incoming requests with validation, but ideally would like to be able to redirect the user to another route on failure - however I'm not sure how to currently handle that using the validation call as it always seems to simply redirect me back to the original page.
Is there any way I can force it to redirect through to a different route on failure? Or am I forced to use a FormRequest for now for the request validation and convert it into a Data Object afterwards?
Thanks,
Dan
Beta Was this translation helpful? Give feedback.
All reactions