Laravel 重定向为 POST

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45486897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:26:53  来源:igfitidea点击:

Laravel Redirect as POST

laravelredirectpost

提问by Enayet Hussain

Currently my users must get the visit form given by Route::getthen 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::postas post data. This needs to be done by my controller. How can I do this in my controller?

目前,我的用户必须获得由 提供的访问表格,Route::get然后填写它以获取由 提供的结果视图Route::post。我需要创建一个可共享的链接,例如通常在表单页面上填写的 VRM/account/search/vrm/{vrm}在哪里{vrm}。这个 VRM 然后需要重定向到Route::post作为发布数据。这需要由我的控制器完成。我怎样才能在我的控制器中做到这一点?

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

回答by ceejayoz

POSTs cannot be redirected.

POST 无法重定向。

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.

最好的办法是让他们登陆一个页面,该页面包含一个带有<input type="hidden">字段的表单和一些 JavaScript,可以立即将其重新提交到所需的目的地。

回答by Oluwatobi Samuel Omisakin

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.

ps:我不想重复同样的事情。