I have a tricky case ...
Following database query does not work:
DB::table(\'posts\')
->select(\'posts.*\', DB::raw($haversineSQL . \' as distance
You can use manual pagination as having
behaving peculiar with pagination class.
$posts = DB::table('posts')
->select('posts.*', DB::raw($haversineSQL . ' as distance'))
->having('distance', '<=', $distance)
->get();
// Items per page
$perPage = 10;
$totalItems = count($posts);
$totalPages = ceil($totalItems / $perPage);
$page = Input::get('page', 1);
if ($page > $totalPages or $page < 1) {
$page = 1;
}
$offset = ($page * $perPage) - $perPage;
$posts = array_slice($posts, $offset, $perPage);
$posts = Paginator::make($posts, $totalItems, $perPage);
dd($posts);