Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Redirect as POST

Currently my users must get the visit form given by Route::get then fill it in to get back a result view given by Route::post. I need to create a shareable link such as /account/search/vrm/{vrm} where {vrm} is the VRM that is usually filled in on the form page. This VRM then needs to redirected to Route::post as post data. This needs to be done by my controller. How can I do this in my controller?

Routes:

// Shows form view
Route::get('/account/search', 'User\AccountController@getSearch')->name('account.search');
// Shows result view
Route::post('/account/search', 'User\AccountController@runSearch');
// Redirect to /account/search as POST
Route::get('/account/search/vrm/{vrm}', function($vrm) { ???????? });
like image 528
Enayet Hussain Avatar asked Aug 03 '17 14:08

Enayet Hussain


2 Answers

POSTs cannot be redirected.

Your best bet is to have them land on a page that contains a form with <input type="hidden"> fields and some JavaScript that immediately re-submits it to the desired destination.

like image 170
ceejayoz Avatar answered Nov 10 '22 10:11

ceejayoz


You can redirect to a controller action or call the controller directly, see the answer here:

In summary, setting the request method in the controller, or calling a controller's action.

Ps: I don't want to repeat the same thing.

like image 36
Oluwatobi Samuel Omisakin Avatar answered Nov 10 '22 10:11

Oluwatobi Samuel Omisakin