0

I am trying to create a eloquent query to get the user results of an array of user id's. Is there a clean way to accomplish this using elequent instead of chaining wheres like this:

$users = User::where('id', '=', '1')->orWhere('id','=','2')

My array of ids comes from an API call and can contain as many id's as the call passes.

Cheers!

1 Answer 1

2

You want to use whereIn. This lets you pass in an array of IDs.

$userIds = [1, 2];
$users = User::whereIn('id', $userIds)->get();
Sign up to request clarification or add additional context in comments.

1 Comment

Amazing! so simple and clean.. Thank you!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.