我Device和Command模型之间有一对多的关系(每个Device都有很多commands).现在我想使用save()方法更新命令集合.所以,我使用了以下代码:
$device = Device::find(1);
$commands = $device->commands()->whereStatus("pending")->get();
$commands->status = "sent";
$commands->save();
Run Code Online (Sandbox Code Playgroud)
但我得到一个FatalErrorException异常,错误信息是Call to undefined method Illuminate\Database\Eloquent\Collection::save().
换句话说,我正在寻找以下的等效MySQL查询Eloquent:
UPDATE commands SET status = 'sent' WHERE status = 'pending';
Run Code Online (Sandbox Code Playgroud)
使用Laravel 4.2