是否可以更新时间戳(updated_at
除外)并在一次查询中增加一列?我当然可以
->increment('count')
和分别
->update(['last_count_increased_at' => Carbon::now()])
但是有没有一种简单的方法可以一起做。
Product::where('product_id', $product->id)
->update(['count'=> $count + 1, 'last_count_increased_at' => Carbon::now()];
无需先查询并获取计数?
最佳答案
您可以在递增或递减操作期间指定要更新的其他列:
Product::where('id',$id)
->increment('count', 1, ['increased_at' => Carbon::now()]);
这是更有说服力的解决方案。
关于php - 如何在一个 Eloquent 查询中增加和更新列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37666135/