Laravel 5 Message Bags: Checking if There Are Any Messages With isEmpty

April 21, 2018 —John Koster

The isEmpty method is the logical opposite of the any method. It returns a boolean value indicating if the message bag is empty (having no messages). It returns true if the message bag is empty; it returns false if the message bag contains messages.

#Signature

The signature of the isEmpty method is:

1public function isEmpty();

#Example Use

The following examples demonstrate the basic usage of the isEmpty method:

1use Illuminate\Support\MessageBag;
2 
3// Create a new MessageBag instance.
4$messageBag = new MessageBag;
5 
6// true
7$isEmpty = $messageBag->isEmpty();
8 
9$messageBag->addMessage('first', 'The first message');
10 
11// false
12$isEmpty = $messageBag->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.