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

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

Laravel 5

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

public function isNotEmpty();

Example Use

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

use Illuminate\Support\Collection;

// Create a new collection instance.
$collection = new Collection;

// false
$empty = $collection->isNotEmpty();

// Add an item to the collection.
$collection[] = 'First item';

// true
$empty = $collection->isNotEmpty();

// false
$empty = $collection->isEmpty();

Start the Discussion

Leave a comment

Subscribe to our newsletter