简体   繁体   English

在Laravel中设置表的所有值

[英]Setting all values of table in Laravel

I want to set every value of a table at the same time. 我想同时设置一个表的每个值。 It is something like this: 它是这样的:

$items = Item::where("user_id",$user_id)->get();

foreach($items as $item){
$item->propiety = 5;
$item->save();
}

This works but I wonder if there is a better way to do it with Eloquent, as I can think better ways to do it with SQL. 这行得通,但我想知道是否有使用Eloquent的更好方法,因为我可以想到使用SQL的更好方法。

您可以这样进行:

Item::where("user_id", $user_id)->update(['propiety' => 5]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM