How to update a collection using Eloquent Laravel

前端 未结 2 1601
抹茶落季
抹茶落季 2021-02-05 11:04

I have a one to many relationship between Device and Command models (each Device has many commands). Now I want to update a c

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 11:48

    You could try the update method on the \Illuminate\Database\Eloquent\Builder object:

    $queryBuilder = $device->commands()->whereStatus("pending");
    $queryBuilder->update(array("status" => "sent"));
    

提交回复
热议问题