I'm so close to getting this one I can taste it but unfortunately stuck and cant find anyone else in a similar situation (surprisingly!?).
Right...so I am making a search query...which is working fine and I am getting everything I want but I need to paginate results.
The input for the search form is just 3 drop down select fields and the result has to match all 3...here is the code dealing with the search query and pagination:
function searchAllProfiles(Request $request){
$query = User::with('spokenLanguages','workingHours','jobType'); //Eager Load User with extras
$request = $request->all();
$location = $request['work_location'];
if($location != ""){
$results = $query->where('work_location',$location)->paginate(10);
}
$position = $request['position'];
$posResults = JobType::jobs($position)->toArray();
foreach($posResults as $pos){
$arrPosResults[] = $pos['user_id'];
}
if($position != ""){
$results = $query->find($arrPosResults);
$results = new LengthAwarePaginator($results, count($results),10);
}
$salary = $request['salary_range'];
if($salary != ""){
$results = $query->where('expected_salary',$salary)->paginate(10);
}
if(!isset($results)){
return redirect()->to('/profiles');
}
return view('auth.results',compact('results'));
}
The problem arises with the middle one where I am searching for JobType. Unfortunately I need to search a separate table which is associated with the users table but its not as easy as doing a ->where()
Anyway...what I have works and I still get the results although it doesnt actually paginate...I get the box below the results saying go to page 1/2/3...but all of the results get loaded and it doesnt actually render?
If I don't search for jobtype and just one of the other 2 then it all loads fine and without issue...pagination is working correctly...
Thanks!