Eloquent method find()
may accept multiple parameters, and then it returns a Collection of all records found, not just one Model:
1// Will return Eloquent Model2$user = User::find(1);3// Will return Eloquent Collection4$users = User::find([1,2,3]);
1return Product::whereIn('id', $this->productIDs)->get();2// You can do this3return Product::find($this->productIDs)
Tip given by @tahiriqbalnajam
Incase of integer, use whereIn
with limited data range only instead use whereIntegerInRaw
which is faster then whereIn
.
1Product::whereIn('id', range(1, 50))->get();2// You can do this3Product::whereIntegerInRaw('id', range(1, 50))->get();
Tip given by @sachinkiranti