By John Koster
setFormat($format = ':message')
The setFormat
is the logical opposite of the getFormat
method. It allows developers to customize the format used by all methods of the MessageBag
instance. It defines a $format
parameter, whose argument will be used as the value of the new format. If the setFormat
method is called without supplying a value for $format
, it will reset the format to the default value (because of the parameter's default value).
1<?php
2
3use Illuminate\Support\MessageBag;
4
5// Create a new MessageBag instance.
6$messageBag = new MessageBag;
7
8// :message
9$format = $messageBag->getFormat();
10
11// Change the format.
12$messageBag->setFormat('<li>:message</li>');
13
14// <li>:message</li>
15$format = $messageBag->getFormat();
16
17// Reset the format.
18$messageBag->setFormat();
19
20// :message
21$format = $messageBag->getFormat();
#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:
- 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: getFormat
- 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
∎