Laravel批量更新,无需触摸时间戳

Laravel批量更新,无需触摸时间戳,laravel,timestamp,Laravel,Timestamp,如果单次更新,我们可以使用 $variable->timestamps = false; 但是,如果我想批量更新而不触及时间戳,该怎么办呢 \DB::table(with(App::class)->getTable()) ->where('published', true) ->whereNotIn('id', $excludeappsid) ->update(['view' => 0]); 目前我的代码是 $allapps = A

如果单次更新,我们可以使用

$variable->timestamps = false;
但是,如果我想批量更新而不触及时间戳,该怎么办呢

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

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

SQLSTATE[42S22]:未找到列:中的1054未知列“timestaps” “字段列表”

有解决办法吗


谢谢。

由于您的型号,您只需将时间戳标记为false即可

public $timestamps = false;
或者你什么也做不了

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

据我所知,这是不可能的。我认为这根本不可能

但是,您可以直接使用查询生成器,而无需雄辩,这将不会更新时间戳

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

$model=新应用程序; $model->timestamps=false; App::setModel$model ->“出版”的地方,对吗 ->其中不在“id”中,$excludeappsid ->更新['view'=>0];
你是如何在同一个查询中进行选择和更新的?这不是违背了更新的\u at字段的目的吗?通过这个查询,我只想重置页面浏览计数器,所以我不需要更新更新的\u at field如果我用该更改触摸模型,我必须联系这么多的控制器,当你只更新你想要的,而不搜索更新创建的和更新的时会发生什么?通过这个查询,我只想重置页面浏览计数器,所以我不需要更新更新的字段,请解释你的答案。Laravel雄辩的生成器尝试在更新期间添加UpdatedAtColumn,如果模型在列中更新了_,Eloquent Builder会将此列添加到值数组中。在完成此操作时,该方法将检查类属性$model是否使用时间戳。如果您尝试暂时禁用时间戳,则可以在模型实例中将timestamps属性设置为false,并在运行时传递该模型。