How to paginate 2 lists with laravel

0

as I can page 2 lists with their page each one that at the time of paging does not change the data in the 2 lists if only change where I am paging.

    
asked by Daniel Cruz Pablo 13.04.2016 в 19:13
source

1 answer

0

When you create your query with Eloquent you simply add a different word that will be the pager parameter for each list, this is known as $pageName :

$queryLista1->paginate(10, ['*'], 'pagina');

$queryLista2->paginate(5, ['*'], 'paginalista2');

If you want more information about the method, look in Illuminate \ Database \ Eloquent \ Builder.php

/**
 * Paginate the given query.
 *
 * @param  int  $perPage
 * @param  array  $columns
 * @param  string  $pageName
 * @param  int|null  $page
 * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
 *
 * @throws \InvalidArgumentException
 */
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
    $query = $this->toBase();

    $total = $query->getCountForPagination();

    $this->forPage(
        $page = $page ?: Paginator::resolveCurrentPage($pageName),
        $perPage = $perPage ?: $this->model->getPerPage()
    );

    return new LengthAwarePaginator($this->get($columns), $total, $perPage, $page, [
        'path' => Paginator::resolveCurrentPath(),
        'pageName' => $pageName,
    ]);
}
    
answered by 14.04.2016 / 05:20
source