Laravel 4: default error messages

In Laravel 4, how to set the default message format for all application error messages?

I already know how to format a single error message ...

echo $messages->first('email', '<p>:message</p>'); 

... and how to format multiple error messages ...

 foreach ($messages->all('<li>:message</li>') as $message) { // } 

... but I would like to know how (and where) to set the default format for all messages in the application.

+4
source share
2 answers

Not tested, but according to the API :

MessageBag::setFormat('<li>:message</li>');

This means that you can also set it (possibly in your BaseController):

$messages->setFormat('<li>:message</li>');

0
source

If you want to access your application, you can change the default format in the Illuminate/Support/MessageBag.php file line 22 after this php artisan optimize run command

 /** * Default format for message output. * * @var string */ protected $format = '<li>:message</li>'; 

Note If you are updating / installing the composer, you need to change it again.

And if you do not want to do this, you can use seFormat () to set the format of the error message, this must be done in all your views. For example - in your opinion

 $errors->setFormat('<li>:message</li>'); 
-2
source

Source: https://habr.com/ru/post/1489079/


All Articles