Reputation: 3833
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.
Upvotes: 0
Views: 33
Reputation: 146201
You may do it this way:
Item::where("user_id", $user_id)->update(['propiety' => 5]);
Upvotes: 2