tgif's avatar
Level 4

how to get Users with a collection of Ids

Hi, I have a collection containg an array of user Ids

Collection {#214 ▼
  #items: array:4 [▼
    0 => 4
    1 => 1
    2 => 2
    3 => 3
  ]
}

How would you use that to retrieve the corresponding users in a separate collection?

0 likes
1 reply
tgif's avatar
tgif
OP
Best Answer
Level 4
$users = collect(
            DB::table('users')
                ->whereIn('id', $userIds)
                ->get()
        );

Please or to participate in this conversation.