laravel redirect back to post route, i get MethodNotAllowedHttpException


laravel redirect back to post route, i get MethodNotAllowedHttpException



At first on a get request i show a form, on submitting it, it goes to a post url does some working in the controller and then returns another view which has a form. after submitting this form i validate some things and if the validation fails i want to redirect back with some errors but unfortunately laravel isn't allowing me
to redirect back to a post method. Is there any way i can accomplish this?



i have seen this answer on laracast https://laracasts.com/discuss/channels/laravel/redirect-back-to-post-route-i-get-methodnotallowed-exception but i couldn't grasp the recommendation



these are my routes in the order described above.


Route::get('/purchasePacks', 'masterDealerController@purchasePacks')->name('purchasePacks');
Route::post('/confirmPuchasedPacks','masterDealerController@confirmPuchasedPacks');
Route::post('/storeOrder','masterDealerController@storeOrder');



below is the redirection code in the storeOrder method. which redirects back to the post url
```


Alert::message("Unable to complete your payment at the moment.",'Please try again later.',"error");
return back()->withInput();



```





Post Redirect Get
– lagbox
Jun 30 at 6:29





which redirects back to the post url ? redirect always performed on GET request. You can't redirect to /storeOrder because it is POST request.
– rkj
Jun 30 at 10:40


which redirects back to the post url ?


/storeOrder




1 Answer
1



I think the problem is that you are sending a GET request to a POST route. You could do one of a few things that I can think of.



1)
In your controller you can have a static method, storeOrderRedirect(), that handles whatever you need it to on the redirect.


Route::match(array('GET', 'POST'), '/storeOrder', function()
{
AppHttpControllersmasterDealerController::storeOrderRedirect()
});



2)
Just have a post and a get route



3)
I myself would send the data from the form via ajax and not leave the page until I get the response I was looking for instead of using redirects and leaving the page to begin with.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV