I have a simple question and I didn´t find what I need.
I need to calculate the distance between t2 geocode points for a list of Stores. I also need it to be paginat
Use the selectRaw method on the Eloquent model.
selectRaw
Store::selectRaw('*, distance(lat, ?, lng, ?) as distance', [$lat, $lon]) ->orderBy('distance') ->paginate(10);
In that case Laravel asks the database for the amount of rows (using select count(*) as aggregate from stores) which saves your RAM.
select count(*) as aggregate from stores