The Blog

Laravel 5

Laravel 5

Laravel 5 Message Bags: Retrieving the Number of Messages With count

John Koster
John Koster
April 21, 2018

The count method in Laravel's MessageBag class returns the total number of messages stored within the instance. It is implemented to satisfy PHP's Countable interface. Use this method to get the count of messages in a MessageBag instance.

Laravel 5

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

John Koster
John Koster
April 21, 2018

The getMessageBag method is used to get a reference to the MessageBag instance. It is used to satisfy the requirements of the "Illuminate\Contracts\Support\MessageProvider" interface. Here is an example of how it can be used.

Laravel 5

Laravel 5 Message Bags: Setting the Message Format With setFormat

John Koster
John Koster
April 21, 2018

The setFormat method in Laravel's MessageBag class allows developers to customize the format used by all methods of the instance. By providing a value for the $format parameter, developers can define the new format. Calling setFormat without a value will reset the format to the default value. Learn how to use this method with examples in the provided documentation.

Laravel 5

Laravel 5: Message Bags

John Koster
John Koster
April 21, 2018

The "Illuminate\Support\MessageBag" class is a key/value storage system for messages. It can be used to format messages for HTML forms, emails, etc. The class implements the "Illuminate\Contracts\Support\MessageProvider" interface and is extended or implemented by various other classes, such as the "Illuminate\Contracts\Validation\ValidationException" and the "Illuminate\Http\RedirectResponse".

Laravel 5

Laravel 5 View Error Bags: Add a New Message Bag Instance to the View Error Bag With put

John Koster
John Koster
April 21, 2018

The put method is used to add a new MessageBag instance to a ViewErrorBag instance, with a specified key. It can also be used to remove all messages from a MessageBag instance and replace them with new ones. Messages can be set dynamically by assigning a new MessageBag instance to a property of the ViewErrorBag instance.

Laravel 5

Laravel 5 View Error Bags: Determining if a Message Bag Exists With hasBag

John Koster
John Koster
April 21, 2018

Learn how to use the hasBag method in Laravel to determine if a MessageBag instance exists within a ViewErrorBag instance. The method can be called with a key parameter, which is set to default by default. Check out the code example in the article to see how it works.

Laravel 5

Laravel 5 View Error Bags: Determining if There Are Any Error Messages With any

John Koster
John Koster
April 21, 2018

The any method is a convenience shortcut to check if the error message bag contains any messages. It returns a boolean value indicating whether there are messages present or not. Instead of using count() > 0, you can simply use any() to perform certain actions when there are error messages.

Laravel 5

Laravel 5 View Error Bags: Getting all Message Bag Instances With getBags

John Koster
John Koster
April 21, 2018

The getBags method retrieves all the MessageBag instances within the ViewErrorBag instance and returns an associative array. This allows you to retrieve and manipulate error messages in a convenient way. To use it, create a new ViewErrorBag instance, populate it with MessageBag instances, and then call the getBags method to retrieve the array of message bags.

Laravel 5

Laravel 5 View Error Bags: Getting the Message Bag Instance With getBag

John Koster
John Koster
April 21, 2018

Learn how to use the getBag method to retrieve a MessageBag instance based on a provided key. If a MessageBag instance does not exist, a new instance will be returned instead. See code examples that demonstrate the usage and behavior of the getBag method, including accessing a MessageBag instance dynamically. Be aware of the behavior where the getBag method does not set the returned MessageBag instance.

Laravel 5

Laravel 5 View Error Bags: Getting the Number of Error Messages With count

John Koster
John Koster
April 21, 2018

The count method in Laravel's MessageBag class returns the number of messages stored within the default instance of MessageBag. It is specifically handled by the ViewErrorBag instance, and needs to be declared within the ViewErrorBag class itself to satisfy PHP's Countable interface requirements. The example usage shows how the count method operates on the default MessageBag instance and how it can be affected by adding or changing the MessageBag instance.

Latest posts

Where Things get Good: Moving on to Forte Development Phase 1

Wrapping up Forte Phase 0 with the lexer and parser now in private alpha, and kicking off Phase 1 wi...

Read more
Forte Update: Backtracking, Metadata, HTML Validation, and More

A Forte development update: the parser now supports backtracking, improvements to node metadata, ide...

Read more
Parsing HTML and Blade Attributes in Forte

Wrapping up attribute parsing in Forte's HTML parser, from simple HTML attributes to complex, edge-c...

Read more
Switch Statements and Parser Extensions in Forte

Exploring how Forte's parser extensions can be used to handle complex Blade directives like nested s...

Read more
Parsing Blade Comments in Forte

Digging into parsing Blade and HTML comments while building Forte's HTML parser for Laravel Blade.

Read more
Thoughts on HTML Elements and Blade Components in Forte

This week I’m tackling Forte's HTML parser - consolidating Blade, Flux, and Livewire components into...

Read more