相关疑难解决方法(0)

如何使用Eloquent Laravel更新集合

DeviceCommand模型之间有一对多的关系(每个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

laravel laravel-4

16
推荐指数
3
解决办法
4万
查看次数

标签 统计

laravel ×1

laravel-4 ×1