A user searches profiles within a certain km radius i.e. 50 km of which I run function which uses latitude/longitude values to retrieve results (this is a rough search within a square not straight line distance), I then paginate the results.
$query = $this->filterNearby($query, $geocode);
$query = $query->paginate(10);
But for each query I need to run a proper distance using great circle formula (to get accurate 50km) AND the people searched may only willing to travel 20km from their location so I need to remove these from the query.
I have tried to do a $query = $query->get()
prior to pagination, then do a for each to remove items but then the pagination does not work. I have tried to create a new Paginator but am unsure how this works through to the view?
Latest code:
if (\Request::segment(2) == "jobs")
{
$query = $this->searchJob($search_strategy);
$query = $this->filterNearbyJob($query, $geocode);
$query = $this->filterJob($query);
$query = $query->get();
// Foreach function to go here to get accurate distance between two points and remove from query results
$paginate = new Paginator($query, count($query), 10);
$category = $this->getCategoryURL($search_strategy);
$sub_categories = ServiceSubCategory::where('sub_category_url', '=', $search_strategy)->first();
return view('search.job')
->with('category', $category)
->with('sub_categories', $sub_categories)
->with('search_results', $paginate);
}