如果我正在构建查询并添加select语句,那么如果我使用->paginate(50)
(因为->paginate()
使用似乎覆盖现有选择权益的->count()
),它将被覆盖。
即:
$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
我如何克服这个问题?现在只有解决方案是跳过使用paginator。
答案 0 :(得分:0)
当您拥有$users = User::whereActive(1)->paginate(10);
时,分页是否有效?
当我使用addSelect()
时,我在声明查询后使用它,类似于:
$users = User::whereActive(1);
$users->addSelect('my-custom-stuff')->paginate(5);