Find Many

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 Model
2$user = User::find(1);
3// Will return Eloquent Collection
4$users = User::find([1,2,3]);
1return Product::whereIn('id', $this->productIDs)->get();
2// You can do this
3return 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 this
3Product::whereIntegerInRaw('id', range(1, 50))->get();

Tip given by @sachinkiranti

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord