Laravel渴望加载,在得到结果之前计算

时间:2014-10-25 14:15:19

标签: php laravel

我知道这很奇怪,但不知怎的,我想知道是否可能,我正在创建自己的分页,我一直在寻找分页的热切加载,但有人说它仍然无法使用。

    //this query will get the record count
    $qry_counter = LeadsModel::with('emails','contacts','create_by_name','sources');

    //this query will get the data
    $query = LeadsModel::with('emails','contacts','create_by_name','sources');

    if(isset($inputs['page_no']) && isset($inputs['records_per_page']))
    {
        //setting pagination variables
        $paginate_start_record = ($inputs['page_no'] - 1) * $inputs['records_per_page'];

        //get the corresponding results based on the page and records per page
        $query->skip($paginate_start_record)->take($inputs['records_per_page']);
    }

    //loop through condition
    foreach($conditions as $condition)
    {
        $query->orWhere($condition[0],$condition[1],$condition[2]); 

        $qry_counter->orWhere($condition[0],$condition[1],$condition[2]);
    }

    $results_counter = $qry_counter->get()->count();

    $results = $query->get();

有关如何优化此代码的任何建议吗?是否可以先获取总记录数,然后它还会根据设置返回记录并跳过并取出?提前致谢

0 个答案:

没有答案