Load data faster when the targeted value is an integer

Instead of using the ๐˜„๐—ต๐—ฒ๐—ฟ๐—ฒ๐—œ๐—ป() method to load a large range of data when the targeted value is an integer, use ๐˜„๐—ต๐—ฒ๐—ฟ๐—ฒ๐—œ๐—ป๐˜๐—ฒ๐—ด๐—ฒ๐—ฟ๐—œ๐—ป๐—ฅ๐—ฎ๐˜„() which is faster than ๐˜„๐—ต๐—ฒ๐—ฟ๐—ฒ๐—œ๐—ป().

// instead of using whereIn
Product::whereIn('id', range(1, 50))->get();
 
// use WhereIntegerInRaw method for faster loading
Product::whereIntegerInRaw('id', range(1, 50))->get();

Tip given by @LaraShout

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 73 courses
  • 93 long-form tutorials
  • access to project repositories
  • access to private Discord

Recent New Courses