Can I use get and paginate together?
I have a case where I want to get the the data then extract information from it, but also paginate it.
In my case I want to pluck the id column from the query data
Instead of just doing 2 queries (for the get and pagination, though not big deal)
Whats the use case ? Sounds like it is just going to be really slow
@Sinnbeck I want to pluck the ids column, and use the id array in another whereIn query
@Ligonsker So the pagination is on the second query?
$ids = User::where('foo', $bar)->pluck('id');
$posts = Post::whereIn('user_id', $ids)->paginate(20);
@Ligonsker a whereIn subquery can solve this; e.g.
User::whereIn('id', function($builder) {
$builder->select('user_id')->from('posts');
})->paginate();
Now, you have only one query
@tykus Oh I need to try it out, looks nice
@Sinnbeck That should work as well, I'm also curious if @tykus would fit in my case
@Ligonsker I belive it would yes. It's just inside a single query
Please or to participate in this conversation.