Laravel PUT 请求参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35863204/
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 13:22:19  来源:igfitidea点击:

Laravel PUT request parameter

laravel

提问by Sang Tr?n

When the route is:

当路线是:

  Route::post('/abcd',...); 

Then in controller I get the parameter like this:

然后在控制器中我得到这样的参数:

   $r->get('param')   // with Request $r

But while the route is of a PUTrequest type:

但是虽然路由是PUT请求类型的:

   Route::put('/abcd,...);

That code doesn't work. It doesn't get the value of parameter.

该代码不起作用。它没有得到参数的值。

回答by Arthur Khusnullin

Try setting x-www-form-urlencoded for body in the postman.

尝试在邮递员中为 body 设置 x-www-form-urlencoded 。

回答by Khesayed

Set method to POST and add _method field with PUT valueenter image description here

将方法设置为 POST 并添加具有 PUT 值的 _method 字段在此处输入图片说明

回答by Awais Jameel

<input type="hidden" name="_method" value="PUT">

Just added an extra field in form. works perfect!

刚刚在表单中添加了一个额外的字段。工作完美!

回答by Random5000

If submitting an API request and you don't want your developers to send a POSTrequest with _method=PUTrequest variable, see solution here: https://github.com/laravel/framework/issues/13457#issuecomment-341973180

如果提交 API 请求并且您不希望开发人员发送POST带有_method=PUT请求变量的请求,请参阅此处的解决方案:https: //github.com/laravel/framework/issues/13457#issuecomment-341973180

回答by mshakeel

Route:

路线:

$api->put('photos', 'App\Api\V1\Controllers\PhotoController@updatePhoto');

Controller code:

控制器代码:

public function updatePhoto(Request $request)
{
    $paramValue = $request->get('param_name');
}

Working fine for me.

对我来说工作得很好。