// This worksif ( 0 === $model->where('status', 'pending')->count() ) {} // But since I don't care about the count, just that there isn't one// Laravel's exists() method is cleaner.if ( ! $model->where('status', 'pending')->exists() ) {} // But I find the ! in the statement above easily missed. The// doesntExist() method makes this statement even clearer.if ( $model->where('status', 'pending')->doesntExist() ) {}
Tip given by @ShawnHooper
Enjoyed This Tip?
Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.
Recent Courses
Building a Typical Laravel SaaS
13 lessons
1 h 58 min
How to Build Laravel 12 API From Scratch
28 lessons
1 h 21 min
Filament 4 From Scratch
28 lessons
2 h 25 min