Laravel Version: 5.5
PHP Version:7
Hi, I want to execute this query:
select (case
when(title like 'my-keyword') then 1
when(description like 'my-keyword') then 2
) as ordering from products where id > 10;
When I do this by query builder:
$products = DB::table('products')->select(DB::raw('(case
when(title like "?") then 1
when(description like "?") then 2
) as ordering'))->where('id', '>', 10)->setBindings(['my-keyword', 'my-keyword'])->paginage(10);
this will going to get count and as we know this will remove all select part and replace it with count(*) as aggregate so if I use setBindings on this query builder and pass ['my-keyword', 'my-keyword'] to this query for aggregate will change to this:
select count(*) as aggregate from products where id > my-keyword;
So this will cause the problem of using pagination on this query and other alternatives like this query!
To solve the problem I changed some codes in /..../Query/Builder.php this:
$total = $this->getCountForPagination($columns);
to this:
$all = $this->get();
$total = $all->count();
for this situation I know it's wrong but for now it works!
what should I do to resolve this problem in a correct way?!