Following database query does not work:
DB::table('posts')
->select('posts.*', DB::raw($haversineSQL . ' as distance'))
->having('distance', '<=', $distance)
->paginate(10);
It fails with message: column distance does not exist.
The error occurs when paginate() tries to count the records with
select count(*) as aggregate from {query without the column names}
As the column names are stripped, distance is not known and an exception is raised.
Does somebody have a work around to be able to use pagination is this case ?