我想在自定义laravel查询中添加分页。 这是我的代码。
$jobseekers = Jobseeker::where('employer_id', Auth::employer()->get()->id)->get()->toArray();
$jobs = Job::select('id')->where('employer_id', (Auth::employer()->get()->id))->get()->toArray();
$apps = DB::table('applications')
->leftJoin('jobseekers', 'applications.jobseeker_id', '=', 'jobseekers.id')
->groupby('jobseekers.id')
->whereIn('applications.job_id', $jobs)
->get();
$apps_array = array();
for ($i = 0; $i < count($apps); $i++) {
$apps_array[$i] = (array) $apps[$i];
}
$jobseeker = array_merge($jobseekers, $apps_array);
return view('frontend.manageCV', compact('jobseeker', 'assignJS'));
答案 0 :(得分:1)
试试这个,看看它是怎么回事
// I have changed the get to paginate
$jobseekers = Jobseeker::where('employer_id', Auth::employer()->get()->id)->paginate();
$jobs = Job::select('id')->where('employer_id', (Auth::employer()->get()->id))->get()->toArray();
$apps = DB::table('applications')
->leftJoin('jobseekers', 'applications.jobseeker_id', '=', 'jobseekers.id')
->groupby('jobseekers.id')
->whereIn('applications.job_id', $jobs)
->get();
$apps_array = array();
for ($i = 0; $i < count($apps); $i++) {
$apps_array[$i] = (array) $apps[$i];
}
// I am merging to the $jobseekers->data in $jobseekers array
$jobseekers->data = (object)array_merge((array)$jobseekers->data, $apps_array);
return view('frontend.manageCV', compact('jobseekers', 'assignJS'));