Laravel Redirect as POST

Viewed 37426

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) { ???????? });
4 Answers

For those who comes later: If you are using blade templating engine for the views, you can add '@csrf' blade directive after the form starting tag to prevent this. This is done by laravel to prevent cross site reference attacks. By adding this directive, you can get around this.

return redirect()->route('YOUR_ROUTE',['PARAM'=>'VARIABLE'])
Related