-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Pagination not working if query contain HAVING statement #3105
Comments
See http://stackoverflow.com/a/20945960/2490608 for a workaround if you're interested. |
Closing this as duplicate. |
Hello sir i am getting this problem in laravel 5.3.. i am stuck on this from long..please solve. |
my query is as follwing $properties = \DB::table('properties')->select(\DB::raw("*,( 6371 * acos( cos( radians($this->user_lat) ) * cos( radians( |
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'having clause' (SQL: select count(*) as aggregate from |
use ->simplePaginate();
It's faling due to the having clause in your query, |
Now here an other solution...
In your controller...
|
Why is this question closed? The problem still exists. Using paginator and having at the same query makes it crash. |
According to the comment above, it is a duplicate of another issue. |
Probably more accurately closed as a wontfix because of #5515 |
iit's simple change paginate(10) with simplePaginate(10) |
What I've done (Laravel 5.5) is overwritten
Update: I've created a package for this: https://github.com/justbetter/laravel-pagination-with-havings |
Hi $data = DB::table('jobs as j') $data = $data->paginate(10); Please help me |
@jayantakundu change paginate(10) to simplePaginate(10) if you work with having. |
I am using laravel api resource in my api & using Resource::collection to get paginated api response. But if i change this paginate to simplePaginate, in the api response some attributes missing in pagination links & meta as generated from paginate method. |
Just ran into this issue in 5.6 @royduin solution seemed to fix it so cheers! Is there any actual planned fix for this? |
Same Here, @royduin seems to fix it. Any plans to put this into the source code? |
@royduin How you override QueryBuilder? |
@solofeed I'm currently with vacation, when I'm back next week I'll share it, create a PR or a module for this. |
@royduin sry for this, thank you) have a nice vacation) |
I'm back @solofeed and I've created a package for it: https://github.com/justbetter/laravel-pagination-with-havings |
Thank you @royduin for your great work . |
Whenever I had this problem, the following worked fine for me, though I'm not sure whether this is a general solution: Though this is probably pretty inefficient on large result sets, as MySQL will now load the entire subquery into working memory. |
Thank you so much @royduin . |
@royduin thank you |
I have a query that return the cities on a fixed distance from a point:
This cause this mysql error:
Because the agregate query generated by the pagination class contain the having but not the select (distance)
The text was updated successfully, but these errors were encountered: