Maurício Giordano
Maurício Giordano

Reputation: 3276

Retrieve results in array Laravel 4

I want to, given a set of ids - ex:

array(500) {
  [0]=>
  string(7) "5700266"
  [1]=>
  string(9) "514803345"
  [2]=>
  string(9) "527286881"
  [3]=>
  string(9) "533641181"
  [4]=>
  string(9) "533793077"
  ...
}

execute a query that checks which ids exists on db.

I've tried to use eager load but couldn't make it work.

Basically I need to retrieve all users in that array set. (I'm trying to avoid doing it user by user).

Thanks!

Upvotes: 0

Views: 32

Answers (1)

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

You probably will be able to do it by

$users = User::whereIn('id', $yourArrayOfIds)->get();

Upvotes: 1

Related Questions