crazymonster's avatar

L5: Pagination Problem

Hello, guys.

My Controller:

    use Illuminate\Pagination\LengthAwarePaginator as Pagination;
    $count = count($singers);

        $singers = new Pagination($singers, $count, 2);
        return view('singers.view', compact("countries", "singers"));

My View:

$singers->setPath('/admin/singers/view');
echo $singers->appends(['visible' => '', 'country' => ''])->render();

So, it change query parameter 'page', but there have render of all results.

Btw, count of pages, which are rendered replies to count of total items/perPage.

I saw a lot of implementations, incl. in Laravel 5 Docs, but they use ->paginate(), and the method doesn't exist in Eloquent\Common::paginate();

I think, will be very easy and simple... it's Laravel.

So, how it works?

0 likes
1 reply
crazymonster's avatar

I find the problem. In my query I used ->get()

It's not need: Example

SingerModel::leftjoin('users', 'users.id', '=', 'singers.user_id')
                ->select('users.name as username', "singers.*")
            ....
                ->orderBy("singers.name", "ASC")
                ->orderBy("singers.id", "DESC")
                ->paginate(2);

paginate(2) executes all results.

My previous query was:

SingerModel::leftjoin('users', 'users.id', '=', 'singers.user_id')
                ->select('users.name as username', "singers.*")
            ....
                ->orderBy("singers.name", "ASC")
                ->orderBy("singers.id", "DESC")
        ->get()
                ->paginate(2);
```


I hope to help someone.

Please or to participate in this conversation.