Last active
March 9, 2021 03:53
-
-
Save lezhnev74/84fef07a43e79bfc490d4cff8d17c05e to your computer and use it in GitHub Desktop.
Replace custom placeholder in Validation message (Laravel)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// When I create a validation rule, I can set my one replacer which helps replace different special placeholders | |
// For example if validator message is "Problem with :some", then my replacer will handle it | |
Validator::extend('testrule', function($attribute, $value, $parameters, $validator) { | |
$validator->addReplacer('testrule', function($message, $attribute, $rule, $parameters){ | |
return str_replace(":some", "whatever", $message); | |
}); | |
return $value == "test"; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about passing the value to the message. Instead of
return str_replace(":some", "whatever", $message);
I want to do something like:
return str_replace(":some", $someValue , $message);
Any ideas?
Thanks