I've a custom validation rule added to AppServiceProvider boot() method as following:
Validator::extend('validate_item', function($attribute, $value, $parameters, $validator) use($service) {
try {
$service->checkItem($value);
}catch (ItemNotFound $e){
return false;
}catch(MultipleExists $e){
return false;
}
return true;
});
as you can see checkItem($value) method throws two exceptions depending on if item not exists or if multiple items exists with the same $value.
I want to show different messages according to the exception. Is there a built in way to do this? I don't want to make two validation rules becoz the $service->checkItem() method is resource expensive, contacts a remote service.
Documentation only talks about using a single message, and :attribute re-placer if needed
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire