Laravel 5 Message Bags: Returning the Message Bag Instance With getMessageBag

April 21, 2018 —John Koster

The getMessageBag method returns a reference to the MessageBag instance. It exists to satisfy the requirements of the "Illuminate\Contracts\Support\MessageProvider" interface.

#Signature

The signature of the getMessageBag method is:

1public function getMessageBag();

#Example Use

The following example demonstrates the usage of the getMessageBag method:

1use Illuminate\Support\MessageBag;
2 
3// false
4$isEqual = ($messageBag === $anotherMessageBag);
5 
6// true
7$isEqual = ($messageBag === $messageBag->getMessageBag());

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.