Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
showing :value in laravel validation errors
//in controller
$validator = Validator::make(['one','two','three'], [
'*' => 'exists:table,name',
], [
'exists' => '`:value` does not exist.',
]);
//in service provider boot
$this->app->validator->resolver(function($translator, $data, $rules, $messages, $attributes)
{
return new CustomValidator($translator, $data, $rules, $messages, $attributes);
});
//CustomValidator
use Illuminate\Validation\Validator;
class CustomValidator extends Validator
{
/**
* Replace all place-holders for the view_exists rule.
*
* @param string $message
* @param string $attribute
* @param string $rule
* @param array $parameters
* @return string
*/
protected function replaceExists($message, $attribute, $rule, $parameters)
{
return str_replace(':value', $this->getValue($attribute), $message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.