【发布时间】:2015-05-19 07:59:09
【问题描述】:
在 laravel 5 上使用查询生成器进行更新时遇到问题。我尝试禁用 updated_at 但一直失败。
这是我的代码:
$query = StockLog::where('stock_id', $id)->whereBetween('created_at', $from, $to])->update(['batch_id' => $max + 1]);
我尝试了两种方法: 我设置的第一个模型:
public function setUpdatedAtAttribute($value)
{
/*do nothing*/
}
第二个:
$stocklog = new StockLog;
$stocklog->timestamps = false;
$query = $stocklog::where('stock_id', $id)->whereBetween('created_at', [$from, $to])->update([
'batch_id' => $max + 1]);
他们都失败了。无论如何禁用updated_at?
提前致谢
【问题讨论】:
-
永久关闭它?还是只针对一个特定的查询?
-
嗨。永久关闭。 @TheShiftExchange
-
当你说“他们两个都失败了”——实际的失败/错误是什么?
-
找不到列:1054 '字段列表'@TheShiftExchange 中的未知列'updated_at'
-
如果您根本不想拥有它,那么最好不要在迁移中拥有它。如果您正在使用迁移,您可能会有类似
$table->timestamps();的内容,您可以在模型中设置此public $timestamps = false;并手动添加 created_at
标签: php laravel laravel-4 laravel-5