I'm creating my first package for lumen 6.x. I'm able to use my own translated messages from /resources/lang/es/messages.php within my package but for some reason, validation messages are not working, in fact, the /resources/lang/es/validation.php is ignored.
I'm guessing that's something related to the way that validator is implemented in the controller since translations are correctly loaded from my Provider, therefore I assume that it's being loaded too.
My /resources/lang/es/validation.php looks like:
<?php
return [
'required' => 'El campo :attribute es obligatorio.',
];
My boot function within service provider:
public function boot()
{
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'locations');
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
// Publishing is only necessary when using the CLI.
if ($this->app->runningInConsole()) {
$this->bootForConsole();
}
}
The store function in Controller
public function store(Request $request)
{
//
$validator = Validator::make($request->all(), [
'name' => 'required'
]);
if ($validator->fails()) return $validator->errors();
$resource = Country::create($request->toArray());
return response()->json([
'message' => __('locations::messages.store_success'),
'resource' => $resource
]);
}
Also in my main .env lumen file I've added APP_LOCALE=es which works perfect for translations.
So the problem is that I'm not able to show translated message for required name field.
BTW, con can look the whole code in my testing git repository (Please ignore States and Cities stuff since it under development). https://github.com/Imboga/Locations
Thanks in advance
Edit: I also tried with this, but no luck so far
public function store(Request $request)
{
//
$this->validate($request, [
'name' => 'required'
]);
$resource = Country::create($request->toArray());
return response()->json([
'message' => __('locations::messages.store_success'),
'resource' => $resource
]);
}