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

Repeat/echo the value of the failed rule in the error message? #377

Open
RickKukiela opened this issue May 17, 2024 · 0 comments
Open

Repeat/echo the value of the failed rule in the error message? #377

RickKukiela opened this issue May 17, 2024 · 0 comments

Comments

@RickKukiela
Copy link

I'm sorry if this is answered somewhere, I tried searching here and read the Readme twice, and analyzed the error method in the src and cannot figure out how to do this, or if it's even possible.

Currently I can repeat back the name of the field that failed its validation in the error message by using {field}, however for debugging purposes I was trying to add {value} and it does not work. I checked the error() method at runtime and the $values array that gets passed is empty so the $params array it creates for the vsprintf call is empty.

How can I write my rule so the $values param that is passed to the error method is populated?

Here is the code I am currently using:

        $this->validator->rule('required', 'primaryNtpServer');
        $this->validator->rule('optional', 'secondaryNtpServer');
        $this->validator->rule(function ($field, $value) {
            if ($field === 'secondaryNtpServer' && empty($value)) {
                return true;
            }
            return Services::dateTime()::verifyNtpdServer($value);
        }, ['primaryNtpServer', 'secondaryNtpServer'], [)->message('{field} "{value}" did not respond to an NTP request.');
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