在整数上调用成员函数 update() - Laravel

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

Call to a member function update() on integer - Laravel

laravellaravel-5sql-update

提问by Andre

I call the update function in my controller so I can apply the changes to advert from the edit form template. I get the following error.

我在控制器中调用更新函数,以便我可以将更改应用到编辑表单模板中的广告。我收到以下错误。

Call to a member function update() on integer

在整数上调用成员函数 update()

This is my update controller code

这是我的更新控制器代码

public function update(Request $request, $id){
      PropertyAdvert::where('id', $id)->where('user_id', Auth::id()->update
      ([
        "photo"       => base64_encode(file_get_contents($request->photo->path())),
        "address"     => $request->address,
        "county"      => $request->county,
        "town"        => $request->town,
        "type"        => $request->type,
        "rent"        => $request->rent,
        "date"        => $request->date,
        "bedrooms"    => $request->bedrooms,
        "bathrooms"   => $request->bathrooms,
        "furnished"   => $request->furnished,
        "description" => $request->description,
        "user_id" => Auth::id(),
      ]));

      return back();
    }

My edit form is quite big so I don't think I should post this.

我的编辑表格很大,所以我不认为我应该发布这个。

Any ideas?

有任何想法吗?

回答by DevK

It's a typo. You're calling ->updateon Auth::id(), not the query. Move the last bracket the bracket before ;to end the ->where(..)part.

这是一个错字。你调用->updateAuth::id(),而不是查询。将最后一个支架移动到支架之前;以结束->where(..)零件。

Here, this should work:

在这里,这应该有效:

PropertyAdvert::where('id', $id)->where('user_id', Auth::id())->update([
    "photo"       => base64_encode(file_get_contents($request->photo->path())),
    "address"     => $request->address,
    "county"      => $request->county,
    "town"        => $request->town,
    "type"        => $request->type,
    "rent"        => $request->rent,
    "date"        => $request->date,
    "bedrooms"    => $request->bedrooms,
    "bathrooms"   => $request->bathrooms,
    "furnished"   => $request->furnished,
    "description" => $request->description,
    "user_id" => Auth::id(),
]);