如果我正在构建一个查询并添加一个select语句,那么如果我使用->paginate(50)
,它将被覆盖(因为->paginate()
使用的->count()
似乎覆盖了现有的select赌注)。
即:
$users = User::whereActive(1)->addSelect('some-custom-select-statement')->paginate(10); // wont work. 'some-custom-select-statement' will not be returned
或者如果我真的这么做了:
$users = User::whereActive(1)->addSelect('some-custom-select-statement')->having('some-custom-select-statement', '>', 0)->count(); // wont work. 'some-custom-select-statement' will not be returned
我该如何克服这一点?目前唯一的解决方案是跳过使用分页器。
只有$users = User::whereActive(1)->paginate(10);
时分页是否有效?
当我使用addSelect()
时,我在声明查询后使用它,类似于:
$users = User::whereActive(1);
$users->addSelect('my-custom-stuff')->paginate(5);