Laravel Eloquent - update() 函数

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

Laravel Eloquent - update() function

laraveleloquent

提问by Kousha

Laravel's Eloquent update()function returns a boolean, and not the updated entry. I'm using:

Laravel 的 Eloquentupdate()函数返回一个布尔值,而不是更新后的条目。我正在使用:

return User::find($id)->update( Input::all() )

And this returns only a boolean. Is there a way I can get the actual row, without running another query?

这仅返回一个布尔值。有没有办法可以在不运行另一个查询的情况下获取实际行?

回答by fmgonzalez

I think that's the behaviour that you want:

我认为这就是你想要的行为:

$user = User::find($id)->fill(Input::all());
return ($user->update())?$user:false; 

I hope it works fine for you.

我希望它对你有用。