archvist
archvist

Reputation: 722

Laravel Eloquent query fetch all results where id equals array

I'm trying to fetch all the data from my database where the id is equal to the id in an array. I want this to run in a sequential order for example if the array is called $attributes and looks like this;

array:2 [▼
  0 => 11
  1 => 12
]

I want to fetch all the results where the id is equal to 11 and group those together to loop through later. Then move on and query the DB for all the results where the id is equal to 12.

I could create a loop and run a query over each iteration but if the array has 30+ id's that will result in 30 queries which are essentially the same just matching a different id.

Can I pass an array to a where or clause and chunk the results so I can loop thought it grouped later?

Upvotes: 0

Views: 4926

Answers (0)

Related Questions