Laravel 5 Message Bags: Determining if There are Any Messages With any

April 21, 2018 —John Koster

The any 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.

#Signature

The signature of the any method is:

1public function any();

#Example Use

The following code examples demonstrate the usage of this fairly simple method:

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

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.