Summer Sale! All accounts are 50% off this week.

Ligonsker's avatar

Is it possible to pluck columns from paginated data?

Hello,

Is it possible to get specific column as array from paginated data? For example:

$paginated_data = DB::table('table')->select('id', 'user_id', 'name', 'email')->paginate();

and somehow get the list of user_id's as array from that specific paginated page?

thanks

0 likes
2 replies
Ligonsker's avatar

Update: I found a way to do it:

$plucked_column = ($paginated_data->items())->pluck('user_id');

Is there a better way to do it?

Snapey's avatar

should be able to do

$plucked_column = $paginated_data->pluck('user_id');

but do you need them in a separate array? when you can do the above wherever you need it. For example;

foreach($paginated_data->pluck('user_id') as $userId)

Please or to participate in this conversation.