Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My Translations Not Loaded When Upgrading to v5.2.2 #109

Open
tareq-alqadi opened this issue Sep 28, 2024 · 0 comments
Open

My Translations Not Loaded When Upgrading to v5.2.2 #109

tareq-alqadi opened this issue Sep 28, 2024 · 0 comments

Comments

@tareq-alqadi
Copy link

After upgrading to v5.2.2, my translations are not loaded anymore. The problem lies with the third argument passed to Validator::extend.

Problem Code:

    Validator::extend('currency_code', function ($attribute, $value, $parameters, $validator) use(&$currency_code) {
        $status = false;

        $currency_code = $value;

        $currencies = config('money.currencies');

        if (array_key_exists($value, $currencies)) {
            $status = true;
        }

        return $status;
    },
        trans('validation.custom.invalid_currency', ['attribute' => $currency_code])
    );

Suggested Solution:
To fix this, use the Validator::replacer method to dynamically load translations during validation:

    Validator::extend(
        'currency_code',
        function ($attribute, $value, $parameters, $validator) {
            $status = false;

            $currencies = config('money.currencies');

            if (array_key_exists($value, $currencies)) {
                $status = true;
            }

            return $status;
        }
    );

    Validator::replacer('currency_code', function ($message, $attribute, $rule, $parameters) {
        return trans('validation.custom.invalid_currency', ['attribute' => $attribute]);
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant