Salam,答案:这取决于您何时调用 count 方法!在您的代码中:$model=Model::query();$model2 = $model;foreach ($Entities as $entity) {//you should save your where between in self $model varriable $model = $model->orWhereBetween("id",$entity->first_id,$entity->last_id])}//$model - object of query builder$model->count();//After operations and filtering $model2->count();//Before operations and filtering ( It is equal or more than $model->count() )我希望这可以帮助你 :)
$model=Model::query() foreach ($Entities as $entity) { $model->orWhereBetween("id",$entity->first_id,$entity->last_id]) }//$model - object of query builder$model->count();它将生成一个查询并在 db 端进行计算: SELECT COUNT(*) FROM table WHERE id BETWEEN ? AND ? OR id BETWEEN ? AND ? OR id BETWEEN ? AND ?