Using the doesntExist() method in Laravel

1// This works
2if ( 0 === $model->where('status', 'pending')->count() ) {
3}
4 
5// But since I don't care about the count, just that there isn't one
6// Laravel's exists() method is cleaner.
7if ( ! $model->where('status', 'pending')->exists() ) {
8}
9 
10// But I find the ! in the statement above easily missed. The
11// doesntExist() method makes this statement even clearer.
12if ( $model->where('status', 'pending')->doesntExist() ) {
13}

Tip given by @ShawnHooper

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