2 回答
TA贡献1795条经验 获得超7个赞
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() )
我希望这可以帮助你 :)
TA贡献1811条经验 获得超4个赞
$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 ?
- 2 回答
- 0 关注
- 179 浏览
添加回答
举报