Laravel 5 Collections: Checking If a Collection Contains Items With isNotEmpty

April 22, 2018 —John Koster

The isNotEmpty method is the logical opposite of the isEmpty method; and it will return a boolean indicating whether or not the collection is not empty.

#Signature

1public function isNotEmpty();

#Example Use

The following example demonstrates the basic usage of the isNotEmpty method:

1use Illuminate\Support\Collection;
2 
3// Create a new collection instance.
4$collection = new Collection;
5 
6// false
7$empty = $collection->isNotEmpty();
8 
9// Add an item to the collection.
10$collection[] = 'First item';
11 
12// true
13$empty = $collection->isNotEmpty();
14 
15// false
16$empty = $collection->isEmpty();

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.