April 21, 2018 —John Koster
The count
method returns the total number of messages stored within the MessageBag
instance. The count
method exists to satisfy the requirements of PHP's Countable
interface.
The signature of the count
method is:
1public function count();
The following example shows the usage of the count
method:
1use Illuminate\Support\MessageBag; 2 3// Create a new MessageBag instance. 4$messageBag = new MessageBag; 5 6// Add a few messages to the MessageBag instance. 7$messageBag->add('first', 'This is a message'); 8$messageBag->add('first', 'I am also a message -.- '); 9$messageBag->add('second', 'Can I join, too?');10 11// 312$count = $messageBag->count();
It can be seen in the above example that the count
message counts the number of messages (which is 3
), not necessarily the number of keys (which is 2
).
∎
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.