What do you mean by control? What exactly you want to do after request validation?
Form Request Validation Redirect
How can I control the redirection after a Form Request Validation? Which is the class/method that make redirection?
if validation fails then an exception is thrown. You would need to intercept that if you want to change default behaviour
I'm usin AMP so my forms send a XHR request and wait for a JSON response and then eventually redirect. If I use Form Request Validation when the validation fails I get an error in AMP.
@SNAPEY - Thanks, but how can I intercept the exception in Form Request class?
trap the request in the form request and make sure that it expects json response.
eg
public function rules()
{
dd(request()->wantsJson());
return [....
You are expecting json I think - not 100% sure with AMP
I read in documentation that for AJAX requests Form Request Validation already returns JSON. However I need return something like belove using Form Request Validation:
return response()->json([
'aaa' => 'bbb'
])->withHeaders([
'AMP-Access-Control-Allow-Source-Origin' => 'https://127.0.0.1',
'Access-Control-Expose-Headers' => 'AMP-Access-Control-Allow-Source-Origin',
]);
It only returns json if it recognises the request as ajax, which it does by checking the Accept header in the request.
@SNAPEY - Where the default json response is created in code? And where can I intercept it to add headers?
So you are getting a json response, but missing the AMP headers?
I would first validate in the controller and get that working by manually validating. Then you can move from a working position to getting the same working with a form request
https://laravel.com/docs/5.8/validation#manually-creating-validators
Please or to participate in this conversation.