Find Many and return specific columns

Eloquent method find() may accept multiple parameters, and then it returns a Collection of all records found with specificied columns, not all columns of model:

1// Will return Eloquent Model with first_name and email only
2$user = User::find(1, ['first_name', 'email']);
3// Will return Eloquent Collection with first_name and email only
4$users = User::find([1,2,3], ['first_name', 'email']);

Tip given by @tahiriqbalnajam

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