April 21, 2018 —John Koster
The hasBag
method is used to determine if a MessageBag
instance exists within the ViewErrorBag
instance with the given $key
. The $key
is set to default
unless it is changed. The following example will highlight the usage of the hasBag
method.
The signature of the hasBag
method is:
1public function hasBag(2 $key = 'default'3);
The following example demonstrates the usage of the hasBag
method is:
1use Illuminate\Support\ViewErrorBag; 2use Illuminate\Support\MessageBag; 3 4// Create a new ViewErrorBag instance. 5$viewErrorBag = new ViewErrorBag; 6 7// Check if the 'default' MessageBag instance 8// exists. 9//10// false11$doesExist = $viewErrorBag->hasBag();12$doesExist = $viewErrorBag->hasBag('default');13 14// Check if a 'payments' MessageBag instance15// exists.16//17// false18$doesExist = $viewErrorBag->hasBag('payments');19 20// Add a new 'payments' MessageBag instance.21$viewErrorBag->put('payments', new MessageBag);22 23// Check again if the 'payments' MessageBag instance24// exists.25//26// true27$doesExist = $viewErrorBag->hasBag('payments');
∎
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.