Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

How to get list of ids from pagination query of the current page?

Hello,

I have 1 pagination query for every:

$pagination_query = Table1::...->paginate(100);

then I have a second query that needs to use the list of ids from the pagination query:

$second_query = Table2::whereIn('id', $list_of_ids_from_pagination_query);

How can I get the list of ids only from the paginated page so that I get 100 ids and not thousands of ids which will end up in too many bound variables error?

Ty!

0 likes
3 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Try this

$ids = $pagination_query->items()->pluck('id');
1 like
Ligonsker's avatar

@Sinnbeck when I try $pagination_query->items()->pluck('id'); I get error:

Call to a member function pluck() on array.

but when I do it without items() it works:

$pagination_query->pluck('id');

thank you!

Sinnbeck's avatar

@Ligonsker Ah ok exelent :) Was unsure if it would work on the paginator

Remember to make the thread as solved

1 like

Please or to participate in this conversation.