crazymonster's avatar

L5: Paginate works not at all

Hello. My query: ModelStuff->paginate(12);

All is good, I have been received Collection, but when I dump the data, I can see:

LengthAwarePaginator {#226 ▼
#total: 1
#lastPage: 1
#items: Collection {#212 ▶}
#perPage: 12
#currentPage: 1
#path: "http://some.dev/artists/"
#query: []
#fragment: null
#pageName: "page"
}

When I try to access: http://some.dev/artists?page=2 all is good, but doesn't see any pagination links in my view. I'm using $artists->render(); But nothing is happen...

It's really strange, why total and lastPage aren't counted correctly?

0 likes
4 replies
bestmomo's avatar

Because you have no query, so no results, so no pages.

crazymonster's avatar

I have query. All results are visible. All is fine, except view render()

$artists = SingerModel::join('pivot_song_singer', 'singers.id', '=', 'pivot_song_singer.singer_id')
->join('songs', 'songs.id', '=', 'pivot_song_singer.song_id') ->join('countries', 'countries.id', '=', 'singers.country_id')
->select("singers.*", "countries.name as ctr_name", "countries.id as ctr_id", "countries.flag as ctr_flag")->selectRaw('COUNT(songs.id) as cnt')->where("singers.active", 1)->where("singers.is_visible", 1)->groupBy("singers.id")->orderBy("singers.id", "DESC")
        ->paginate(12);
jekinney's avatar

Yes, laravel's paginater doesn't play well with group by.

Please or to participate in this conversation.