2

我提出流利的要求,分页清晰。我的问题是分页请求是在区分请求之前执行的

我的流利请求:

$candidates = DB::table('candidates')
            ->select('candidates.*')
            ->distinct()
            ->join('candidate_region', 'candidates.id', '=', 'candidate_region.candidate_id')
            ->join('candidate_job', 'candidates.id', '=', 'candidate_job.candidate_id')
            ->whereIn('candidate_region.region_id', $inputs['region'])
            ->whereIn('candidate_job.job_id', $inputs['job'])
            ->where('imavailable', '1')
            ->where('dateDisponible', '<=', $inputs['availableDate'])
            ->paginate(15);

我用 DB::getQueryLog() 测试我的请求

$query = DB::getQueryLog($candidates);

$query 显示制作编号页面的分页请求(带有计数):

5 => 
array (size=3)
     'query' => string 'select count(*) as aggregate from `candidates` inner join `candidate_region` on `candidates`.`id` = `candidate_region`.`candidate_id` inner join `candidate_job` on `candidates`.`id` = `candidate_job`.`candidate_id` where `candidate_region`.`region_id` in (?, ?, ?, ?, ?) and `candidate_job`.`job_id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) and `imavailable` = ? and `dateDisponible` <= ?' (length=396)

我的 distinct 请求是在 paginate 之后执行的:

6 => 
array (size=3)
  'query' => string 'select distinct `candidates`.* from `candidates` inner join `candidate_region` on `candidates`.`id` = `candidate_region`.`candidate_id` inner join `candidate_job` on `candidates`.`id` = `candidate_job`.`candidate_id` where `candidate_region`.`region_id` in (?, ?, ?, ?, ?) and `candidate_job`.`job_id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) and `imavailable` = ? and `dateDisponible` <= ? limit 15 offset 15' (length=417)

如何在分页之前执行不同的请求?

谢谢

4

2 回答 2

1

盲猜:试试

DB::table('candidates')->...stuff...->get()->paginate(15)

真正的答案:手动创建分页器:

$candidates = DB::table('candidates')->...stuff...->get();

$paginator = Paginator::make($candidates, count($candidates), 15);
于 2013-06-13T16:38:46.860 回答
0
<?php
     $presenter = new Illuminate\Pagination\BootstrapPresenter($candidates);
     $presenter->setLastPage($totalPages);
?>

@if ($totalPages> 1)
     <ul class="pagination">
          {{ $presenter->render() }}
     </ul>
@endif
于 2014-09-20T20:05:31.447 回答