laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

Validation translates with prefix do not replace custom attributes correctly #1689

Open xkovacikm opened 5 years ago

xkovacikm commented 5 years ago

Hello guys :)

i have a quite problem here. I load validation translation messages from external package. So i had to use loadTranslationsFrom( $somePath, "core") method in ServiceProvider.

Now i want to validate my request by FormRequest, but translates are not resolved!

So in my CustomFormRequest file i did following thing:

public function messages() {
    return [
        'required' => __("core::validation.required" ),
    ];
    }

But if i fill data to attributes array in my validation.php file (in external package):

'attributes' => [
    "name" => "Name",
    "email" => "E-mail",
    "phonenumber" => "Phone number",
    ],

attributes are not replaced in validation error messages because of method getAttributeFromTranslations($name) in Illuminate\Validation\Concerns\FormatsMessages

protected function getAttributeFromTranslations($name)
    {
        return Arr::get($this->translator->trans('validation.attributes'), $name);
    }

there is hardcoded string 'validation.attributes' and in my case there should be 'core::validation.attributes'

Is there possibility to fix this issue somehow? Thanks a lot guys Have a nice day :)

fletch3555 commented 5 years ago

This is less of an "idea" and more of a bug report... I'd recommend asking on larachat/laravel discord/laracasts forums for someone to confirm it then PR a solution(or have someone else do it for you). Or open an issue on the framework repo and let someone there fix it. I'm a fan of community involvement, so I personally prefer the first option, but I guess that's up to you.