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

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

Laravel 5

The isEmpty can be used to determine if the collection has items or not. If the collection has no items, true will be returned, otherwise false will be returned.

Signature

public function isEmpty();

Example Use

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

use Illuminate\Support\Collection;

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

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

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

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

Start the Discussion

Leave a comment

Subscribe to our newsletter