Open Moyhdez opened 6 years ago
Yes, same with the other method, but you can do it with the query builder... DISCLAIMER: did not try it with the fence method but should be VERY similar.
public function index(Request $request)
$requestPage = $request->input('page') ?? 1; // rewrite to $request->input('page') !== null ? $request->input('page') : 1; for older PHP versions
$resultsPerPage = 30;
$places = Place::distance($lat, $lng)
->orderBy('distance', 'ASC')
->skip(($requestPage - 1) * $resultsPerPage)
->take($resultsPerPage)
->get();
return $places;
}
check this package https://github.com/justbetter/laravel-pagination-with-havings
When i try to paginate using scopeFence i get this error:
(2/2) QueryException SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'having clause' (SQL: select count(*) as aggregate from
spots
inner joinfavorites
onspots
.id
=favorites
.spot_id
wherefavorites
.user_id
= 1 having distance BETWEEN 0 AND 150)