Get single column's value from the first result

You can use value() method to get single column's value from the first result of a query

1// Instead of
2Integration::where('name', 'foo')->first()->active;
3 
4// You can use
5Integration::where('name', 'foo')->value('active');
6 
7// or this to throw an exception if no records found
8Integration::where('name', 'foo')->valueOrFail('active')';

Tip given by @justsanjit

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