douchun1961 2017-02-28 19:32
浏览 62

Laravel API补丁方法

I am developing a laravel api and sucessfully made gets, posts, deletes and i am now trying to do the update method using PATCH.

Here is my first try:

public function update($id, Request $request)
{
    $taxes = taxes::find($id);
    $taxes ->fill($request->only(['$request']));
    $taxes->save();
}

And testing it with the follow url on postman

****.local/api/taxes/1?description=test

This obviously doesnt work, i tought i would be able to see the error but i am currently on a different machine but hopefully someone can guide me to correct path to make this update method.

Dont forget its an api, no views/forms.

Thank you.

  • 写回答

2条回答 默认 最新

  • douchuoxuan3177 2017-02-28 19:36
    关注

    You have to specify the body of the query (so the variables you want to change) in the x-www-form-urlencoded tab of the Body tab for your request in Postman.

    You can find a screenshot here: http://img11.hostingpics.net/pics/987644Sanstitre1.jpg (waiting for imgur to be back online)

    You also have an issue in your method, your code should be the following:

    public function update($id, Request $request)
    {
        $taxes = taxes::find($id);
        $taxes ->fill($request->only(['description', 'anyotherfield', '...']));
        $taxes->save();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog