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
CodePudding user response:
You need to transform your array first:
$arr = [
0 => 1,
3 => 4,
];
$indexes = array_values($arr);
Model::whereIn('id', $indexes)->get();
CodePudding user response:
Model::whereIn('id', $array)->get();
CodePudding user response:
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...