The Blog

Laravel

Laravel

Laravel MessageBag Public API: get

John Koster
John Koster
November 29, 2016

The get method in Laravel's MessageBag class retrieves all messages associated with a given key and format. By default, the format is null and uses the format stored within the MessageBag instance. Developers can customize the format by specifying their own. The method returns an array of all the formatted messages. You can learn more about Laravel's ErrorMessageBag component by reading the rest of the articles in the mini-series.

Laravel

Laravel MessageBag Public API: getFormat

John Koster
John Koster
November 29, 2016

The getFormat method is used to retrieve the current format being used by the MessageBag instance. It returns the format as a string. This is the opposite of the setFormat method, which is used to change the format. You can use these methods to customize the way messages are displayed in Laravel's MessageBag component. To learn more about Laravel's MessageBag component and its public API, check out the following articles in this mini-series: - An Introduction to Laravel Message Bags - Laravel MessageBag Public API: add - Laravel MessageBag Public API: all - Laravel MessageBag Public API: any - Laravel MessageBag Public API: count - Laravel MessageBag Public API: first - Laravel MessageBag Public API: get - Laravel MessageBag Public API: getMessageBag - Laravel MessageBag Public API: getMessages - Laravel MessageBag Public API: has - Laravel MessageBag Public API: isEmpty - Laravel MessageBag Public API: jsonSerialize - Laravel MessageBag Public API: keys - Laravel MessageBag Public API: merge - Laravel MessageBag Public API: setFormat - Laravel MessageBag Public API: toArray - Laravel MessageBag Public API: toJson - Laravel MessageBag Public API: __toString

Laravel

Laravel MessageBag Public API: getMessageBag

John Koster
John Koster
November 29, 2016

The getMessageBag method in Laravel returns a reference to the MessageBag instance, which is used to manage error messages. This method is part of Laravel's Illuminate\Contracts\Support\MessageProvider interface. To learn more about Laravel's ErrorMessageBag component and its public API, check out the articles in the mini-series linked at the end of this post.

Laravel

Laravel MessageBag Public API: getMessages

John Koster
John Koster
November 29, 2016

The getMessages method in Laravel's MessageBag component is used to retrieve all the messages stored in the message bag. It returns an array of messages, where each message is associated with a specific key. If there are no messages in the message bag, an empty array is returned. In the example provided, the $messages variable contains an array with two messages, where each message is nested within another array. To learn more about Laravel's ErrorMessageBag component and its public API, you can continue reading the mini-series of articles listed in the "Continue Reading" section.

Laravel

Laravel MessageBag Public API: has

John Koster
John Koster
November 29, 2016

The has method in Laravel's MessageBag class checks if messages exist for a given key. It returns true if messages exist, and false if not. You can use this method to determine if messages are present before performing any further actions. Check out the rest of the articles in this series to learn more about Laravel's ErrorMessageBag component.

Laravel

Laravel MessageBag Public API: isEmpty

John Koster
John Koster
November 29, 2016

The isEmpty method in Laravel's Collection class can be used to check if the collection contains any items. It returns true if the collection is empty and false otherwise. This can be useful for conditionally executing some code based on whether the collection has items or not. You can learn more about Laravel's ErrorMessageBag component by clicking through the rest of the articles listed in the "Continue Reading" section.

Laravel

Laravel MessageBag Public API: jsonSerialize

John Koster
John Koster
November 29, 2016

The jsonSerialize method of Laravel's ErrorMessageBag allows developers to customize how a class is represented when using the json_encode function. This method internally returns the value of the toArray method, which converts the error messages into an associative array. This article provides a mini-series that explores various public methods of the ErrorMessageBag component in Laravel, such as add, all, any, and more.

Laravel

Laravel MessageBag Public API: keys

John Koster
John Koster
November 29, 2016

The keys method in Laravel allows you to retrieve all the keys stored inside a MessageBag instance. In the code example provided, a MessageBag instance is created and items are added to it. Then, the keys method is called to retrieve an array of keys. The resulting array will contain only the keys that were added. If you want to learn more about Laravel's ErrorMessageBag component, you can check out the mini-series of articles provided in the "Continue Reading" section. These articles cover various aspects of the MessageBag public API.

Laravel

Laravel MessageBag Public API: merge

John Koster
John Koster
November 29, 2016

The merge method in Laravel is used to combine the contents of a MessageBag instance with another array or object that implements the MessageProvider interface. This method modifies the original MessageBag instance and returns a reference to it. In the provided examples, the merge method is used to merge an array with a MessageBag instance and merge two MessageBag instances together. The resulting merged messages can be accessed as an array. This article is part of a series on Laravel's ErrorMessageBag component, exploring various methods in the public API.

Laravel

Laravel MessageBag Public API: setFormat

John Koster
John Koster
November 29, 2016

The setFormat method is used to customize the format used by all methods of the MessageBag instance in Laravel. By passing a $format argument, developers can define the new format. If called without a value, it will reset the format to the default value. This method is part of the Laravel ErrorMessageBag component. Continue reading to learn more about Laravel's MessageBag and its public API methods. The articles cover various methods like add, all, any, count, first, get, getFormat, getMessageBag, getMessages, has, isEmpty, jsonSerialize, keys, merge, toArray, toJson, and __toString.

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