使用laravel 5上的查询构建器更新时遇到问题.我已尝试禁用updated_at,但仍然保持失败.
@H_301_1@这是我的代码:
第一个在我的模型我设置:
$query = StockLog::where('stock_id',$id)->whereBetween('created_at',$from,$to])->update(['batch_id' => $max + 1]);@H_301_1@我已经尝试了两种方法:
第一个在我的模型我设置:
public function setUpdatedAtAttribute($value) { /*do nothing*/ }@H_301_1@第二个:
$stocklog = new StockLog; $stocklog->timestamps = false; $query = $stocklog::where('stock_id',[$from,$to])->update([ 'batch_id' => $max + 1]);@H_301_1@他们都失败了.有没有禁用updated_at? @H_301_1@提前致谢
@H_301_1@By default,Eloquent will maintain the created_at and updated_at columns on your database table automatically. Simply add these timestamp columns to your table and Eloquent will take care of the rest.@H_301_1@我真的不建议删除它们.但是如果要使用以下方式. @H_301_1@将以下内容添加到您的模型中:
public $timestamps = false;@H_301_1@这将禁用时间戳. @H_301_1@编辑:看起来你想保留created_at字段,可以覆盖模型中的getUpdatedAtColumn. @H_301_1@使用以下代码:
public function getUpdatedAtColumn() { return null; }