首页 文章

Laravel Mass更新而不触及时间戳

提问于
浏览
0

如果我们可以使用单一更新

$variable->timestamps = false;

但如果我想在不触及时间戳的情况下进行批量更新 .

目前我的代码是

$allapps = App::select('id','name','parent_id','view')->where('published',true)->whereNotIn('id', $excludeappsid)->update(['timestamps' => false],['view' => 0]);

但我得到错误

SQLSTATE [42S22]:找不到列:1054'字段列表'中的未知列'timestamps'

任何解决方案

谢谢 .

2 回答

  • 0

    从您的模型开始,您可以将时间戳标记为false

    public $timestamps = false;
    

    或者你什么也做不了 . :)

    $allapps = App::select('id','name','parent_id','view')
                       ->where('published',true)
                       ->whereNotIn('id', $excludeappsid)
                       ->update(['view' => 0])
    
  • 1

    据我所知,这是不可能的 . 我认为它甚至不可能 .

    但是,您可以在没有Eloquent的情况下直接使用查询构建器,这不会更新时间戳 .

    \DB::table(with(App::class)->getTable())
        ->where('published', true)
        ->whereNotIn('id', $excludeappsid)
        ->update(['view' => 0]);
    

相关问题