Laravel更新方法不存在 [英] Laravel update method does not exist
本文介绍了Laravel更新方法不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
According to the docs, I should be able to update records using update()
https://laravel.com/docs/5.4/queries#updates, but I'm getting the error Method update does not exist
.
Client::findOrFail($id)->update($request->all());
知道为什么吗?
推荐答案
我认为这是因为您正在单个模型对象上使用查询生成器的方法.您无法执行此操作,因为 findOrFail
方法返回的单个对象与查询生成器的方法无关.
I think this is because you are using the query builder's method on a single model object. You cannot do this because the findOrFail
method returns a single object that has nothing to do with query builder's methods.
这样做: Client :: findOrFail($ id)-> first()-> fill($ request-> all())-> save();
这篇关于Laravel更新方法不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文