Laravel Pagination with haversine formula in it
I think that working with a natural language style query builder has sent your implementation a little astray. I don't understand why you need to select a count of rows from a sub-queried result set when you could just count the rows returned from the query itself, without even pulling the result set down into the application.

Outside of that, I find your code hard to read.


Don't mix use of brackets on each side of if-else conditional
Consider using PSR-2 compliant styles


putting start of brackets for functions/methods, conditionals and looping constructs on same line. 
Don't mix snake_case and camelCase within your user-written code.
One instruction per line.

Limit line lengths to ~80 characters.