{"action":"created","issue":{"url":"https://api.github.com/repos/jeffochoa/validator-factory/issues/5","repository_url":"https://api.github.com/repos/jeffochoa/validator-factory","labels_url":"https://api.github.com/repos/jeffochoa/validator-factory/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/jeffochoa/validator-factory/issues/5/comments","events_url":"https://api.github.com/repos/jeffochoa/validator-factory/issues/5/events","html_url":"https://github.com/jeffochoa/validator-factory/issues/5","id":350876069,"node_id":"MDU6SXNzdWUzNTA4NzYwNjk=","number":5,"title":"Custom Validators Using Rule","user":{"login":"jcrawford","id":875341,"node_id":"MDQ6VXNlcjg3NTM0MQ==","avatar_url":"https://avatars1.githubusercontent.com/u/875341?v=4","gravatar_id":"","url":"https://api.github.com/users/jcrawford","html_url":"https://github.com/jcrawford","followers_url":"https://api.github.com/users/jcrawford/followers","following_url":"https://api.github.com/users/jcrawford/following{/other_user}","gists_url":"https://api.github.com/users/jcrawford/gists{/gist_id}","starred_url":"https://api.github.com/users/jcrawford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcrawford/subscriptions","organizations_url":"https://api.github.com/users/jcrawford/orgs","repos_url":"https://api.github.com/users/jcrawford/repos","events_url":"https://api.github.com/users/jcrawford/events{/privacy}","received_events_url":"https://api.github.com/users/jcrawford/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-15T16:27:52Z","updated_at":"2018-09-05T17:53:36Z","closed_at":null,"author_association":"NONE","body":"I have created a custom validator using Rule as described in the Laravel Documentation.  I have the messages method returning the keys for the messages in the lang files, however they are not being looked up from that file.  I cannot use trans() because I am not using Laravel.\r\n\r\nAny idea how I can have the messages returned from the custom validator evaluated?\r\n\r\n```\r\n$validator = $this->factory->make($data, [\r\n    'phone-number' => ['required', new TwilioPhoneNumber($this->twilioSid, $this->twilioToken)]\r\n]);\r\n```\r\n\r\nThis is my messages method from my custom rule class.\r\n\r\n```\r\npublic function message()\r\n{\r\n    if(!$this->twilioClient) {\r\n        return 'validation.phone-number.credentials';\r\n    }\r\n\r\n    return 'validation.phone-number.invalid';\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/jeffochoa/validator-factory/issues/comments/418821939","html_url":"https://github.com/jeffochoa/validator-factory/issues/5#issuecomment-418821939","issue_url":"https://api.github.com/repos/jeffochoa/validator-factory/issues/5","id":418821939,"node_id":"MDEyOklzc3VlQ29tbWVudDQxODgyMTkzOQ==","user":{"login":"jcrawford","id":875341,"node_id":"MDQ6VXNlcjg3NTM0MQ==","avatar_url":"https://avatars1.githubusercontent.com/u/875341?v=4","gravatar_id":"","url":"https://api.github.com/users/jcrawford","html_url":"https://github.com/jcrawford","followers_url":"https://api.github.com/users/jcrawford/followers","following_url":"https://api.github.com/users/jcrawford/following{/other_user}","gists_url":"https://api.github.com/users/jcrawford/gists{/gist_id}","starred_url":"https://api.github.com/users/jcrawford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcrawford/subscriptions","organizations_url":"https://api.github.com/users/jcrawford/orgs","repos_url":"https://api.github.com/users/jcrawford/repos","events_url":"https://api.github.com/users/jcrawford/events{/privacy}","received_events_url":"https://api.github.com/users/jcrawford/received_events","type":"User","site_admin":false},"created_at":"2018-09-05T17:53:36Z","updated_at":"2018-09-05T17:53:36Z","author_association":"NONE","body":"I think I see the issue in the Laravel core but I do not see a way to extend this to resolve the issue.  Basically when using a custom Rule Larvel calls this from within the `validation/Validator::validateAttribute` method:\r\n\r\n```php\r\n    if ($rule instanceof RuleContract) {\r\n        return $validatable\r\n                ? $this->validateUsingCustomRule($attribute, $value, $rule)\r\n                : null;\r\n    }\r\n```\r\n\r\nInside the `validation/Validator::validateUsingCustomRule` method there is this:\r\n\r\n```php\r\n    $this->messages->add($attribute, $this->makeReplacements(\r\n        $rule->message(), $attribute, get_class($rule), []\r\n    ));\r\n```\r\n\r\nInside the `validation/Validator::makeReplacements` method it has this code: \r\n\r\n```php\r\n    public function makeReplacements($message, $attribute, $rule, $parameters)\r\n    {\r\n        $message = $this->replaceAttributePlaceholder(\r\n            $message, $this->getDisplayableAttribute($attribute)\r\n        );\r\n\r\n        $message = $this->replaceInputPlaceholder($message, $attribute);\r\n\r\n        if (isset($this->replacers[Str::snake($rule)])) {\r\n            return $this->callReplacer($message, $attribute, Str::snake($rule), $parameters, $this);\r\n        } elseif (method_exists($this, $replacer = \"replace{$rule}\")) {\r\n            return $this->$replacer($message, $attribute, $rule, $parameters);\r\n        }\r\n\r\n        return $message;\r\n    }\r\n```\r\n\r\nAs you can see it returns a plain message which in this case is just the string of `validation.row.invalid` as that is what I am returning from my custom Rule `messages` method.  Inside my custom rule since I am not using Laravel I do not have access to the `trans()` function helper so I cannot do any of the translations there.  If however I modify the `return $message` line with `return $this->translator->trans($message)` all work just fine and my message is returned from the translation file.\r\n\r\nAny thoughts/feedback on how I could accomplish this using your `ValidatorFactory` package?"}}
{"actor":{"display_login":"jcrawford"}}