Laravel 4到5分页转换

时间:2015-05-01 18:45:24

标签: php laravel laravel-4 pagination laravel-5

我希望将分页从Laravel 4更改为Laravel 5,我解决了使用自定义驱动程序的问题,因此我可以使用Cache:标记文件

我需要将此代码更改为Laravel 5:

Using $this when not in object context

我自己尝试过,但我不知道怎么做,下面的代码是我到目前为止所做的,但是当我使用它时会出现这个错误:

/**
 * Builds paginate query with given parameters.
 * 
 * @param  array   $params
 * @param  integer $page
 * @param  integer $perPage
 * 
 * @return array
 */
public function buildPaginateQuery(array $params, $page = 1, $perPage = 15)
{
    $query = $this->model->table == 'links' ? $this->model->with('Title') : $this->model;

    $query = $this->appendParams($params, $query);

    $count = Cache::remember('count', 2000, function() use ($query)
            {
                return $query->count();
            });

    $totalPages = $count / $perPage;

    $query = $query->skip($perPage * ($page - 1))->take($perPage);

    $query = $query->order(isset($params['order']) && $params['order'] ? $params['order'] : null);

    $query = Cache::tags([$this->model->table, 'pagination'])->remember('pagination', 2000, function() use ($query)
            {
                return $query;
            });

    return array('query' => $query, 'totalPages' => $totalPages, 'totalItems' => $count);
}

当前尝试的代码:

#include<iostream>
#include<experimental/generator>

auto hello()
{
   for (auto ch : "Hello, world\n")
      yield ch;
}

int main()
{
   for (auto ch : hello())
      std::cout << ch;
}

0 个答案:

没有答案