Bayustypryg
Bayustypryg

Reputation: 29

how to multiple where with array?

I have a $data variable, its contents are in the form of an array like this

array:2 [▼
  0 => 1
  3 => 4
]

and I want to find data like this

Model::where('id', $array)->get();

in such a way does not work, then how? maybe you guys have a solution. thanks

Upvotes: 0

Views: 53

Answers (3)

Anoop Babu
Anoop Babu

Reputation: 188

Model::whereIn('id', $array)->get();

Upvotes: 1

Dinesh Parmar
Dinesh Parmar

Reputation: 105

You can use find() method it accepts single id or array of ids. so you can do like this :

Model::find($array);

may it helps you...

Upvotes: 0

Coola
Coola

Reputation: 3142

You need to transform your array first:

$arr = [
  0 => 1,
  3 => 4,
];

$indexes = array_values($arr);

Model::whereIn('id', $indexes)->get();

Upvotes: 1

Related Questions