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

April 21, 2018 —John Koster

The isNotEmpty method returns a boolean value indicating if the MessageBag instance actually has any messages. The method returns true if the instance has messages, otherwise it returns false. The isNotEmpty method is an alias of the any method.

#Signature

The signature of the isNotEmpty method is:

1public function isNotEmpty();

#Example Use

The following method calls are equivalent:

1use Illuminate\Support\MessageBag;
2 
3// Create a new MessageBag instance.
4$messageBag = new MessageBag;
5 
6// false
7$hasAny = $messageBag->any();
8 
9// false
10$isNotEmpty = $messageBag->isNotEmpty();
11 
12$messageBag->addMessage('first', 'The first message');
13 
14// true
15$hasAny = $messageBag->any();
16 
17// true
18$isNotEmpty = $messageBay->isNotEmpty();

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.