0

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

2

3 Answers 3

1

You need to transform your array first:

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

$indexes = array_values($arr);

Model::whereIn('id', $indexes)->get();
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

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...

Comments

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.