Framework: Pagination fails on adding column alias and having condition on alias

Created on 16 Dec 2016  路  3Comments  路  Source: laravel/framework

  • Laravel Version: 5.1.45
  • PHP Version: 5.6
  • Database Driver & Version:Mysql

Description:

Pagination fails on adding column alias and having condition on alias due to the count query that is run without the select query.

Steps To Reproduce:

$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.

Most helpful comment

@funyug thanks, i replaced paginate method with simplePaginate. it works fine.

All 3 comments

  • Laravel Version: 5.5.35
  • PHP Version: 7
  • Database Driver & Version: Mysql

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RomainSauvaire picture RomainSauvaire  路  3Comments

felixsanz picture felixsanz  路  3Comments

JamborJan picture JamborJan  路  3Comments

progmars picture progmars  路  3Comments

YannPl picture YannPl  路  3Comments