Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - Get error message from localized file

I'm creating my own validation and need to retrieve error messages from the localized file(resources/lang/en/validation.php and etc). The main task is to get array of error messages from the appropriate file. Usually, the validator does it and you don't need to worry about it. Does exist a way to get all these messages with no using validator?

like image 745
V-K Avatar asked Dec 12 '25 20:12

V-K


1 Answers

You can access your translation files and their contents from anywhere with the global helper function trans
For example: your translations are in the file resources/lang/en/customvalidation.php

return [
    'customerror' => 'my custom error message',
];

Then

trans('customvalidation.customerror')

will return "my custom error message" (depending on the current set language)

like image 65
MrEvers Avatar answered Dec 16 '25 22:12

MrEvers