Search

Laravel MessageBag Public API: has

November 29, 2016 —John Koster

has($key = null)

The has method can be used to determine if messages exist within the MessageBag instance for a given $key. The has method returns true if messages exist for the given $key, and returns false if no messages exist.

The following examples demonstrate the usage of the has method:

1<?php
2 
3use Illuminate\Support\MessageBag;
4 
5// Create a new MessageBag instance.
6$messageBag = new MessageBag;
7 
8// false
9$hasMessage = $messageBag->has('test');
10 
11// Add the message to the message bag.
12$messageBag->add('test', 'Example message');
13 
14// true
15$hasMessage = $messageBag->has('test');

#Continue Reading

This article is the start of a mini-series about Laravel's ErrorMessageBag component. Click through the rest of the articles to continue reading:

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.