By John Koster
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).
#Signature
The signature of the setFormat
method is:
1public function setFormat(
2 $format = ':message'
3);
#Example Use
The following example demonstrates the usage of the setFormat
method:
1use Illuminate\Support\MessageBag;
2
3// Create a new MessageBag instance.
4$messageBag = new MessageBag;
5
6// :message
7$format = $messageBag->getFormat();
8
9// Change the format.
10$messageBag->setFormat('<li>:message</li>');
11
12// <li>:message</li>
13$format = $messageBag->getFormat();
14
15// Reset the format.
16$messageBag->setFormat();
17
18// :message
19$format = $messageBag->getFormat();
∎