Pagination fails on adding column alias and having condition on alias due to the count query that is run without the select query.
$data = PropertyRent::select(DB::raw('min(rent) as min_rent,property_id'))->groupBy('property_id')->having('min_rent','>=',1000)->paginate();
Error:
Unknown column 'min_rent' in 'having clause' (SQL: select count(*) as aggregate from property_rents group by condominium_id having min_rent >= 1000)'
Note: the get() query works fine.
May we open this issue again ? i have same problem with paginate method on having.
It is mentioned in the laravel docs that pagination doesnt work with groupby statements
https://laravel.com/docs/5.6/pagination
You have to create a paginator manually
@funyug thanks, i replaced paginate method with simplePaginate. it works fine.
Most helpful comment
@funyug thanks, i replaced paginate method with simplePaginate. it works fine.