Home > Mobile >  Laravel : is it possible to pass a locale to Validator
Laravel : is it possible to pass a locale to Validator

Time:08-08

in my laravel controllers I validate requests like this:

$validatedData = $request->validate(UserValidator::$updateIfNeeded);

Now, is it possible to pass a locale string to a validator, like "es" or "en"?

CodePudding user response:

No need to do that, Laravel's built-in validation rules each has an error message that is located in your application's lang/en/validation.php file. Within this file, you will find a translation entry for each validation rule. You are free to change or modify these messages based on the needs of your application.

In addition, you may copy this file to another translation language directory to translate the messages for your application's language. To learn more about Laravel localization, check out the Laravel Documentation https://laravel.com/docs/9.x/validation

CodePudding user response:

If your locale set in your route, you can access to It with request()->LocaleParameter. If you set locale earlier than validator, you can access to it with app()->getLocale() or Config::get('app.locale')

  • Related