{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/ideas/issues/1173","repository_url":"https://api.github.com/repos/laravel/ideas","labels_url":"https://api.github.com/repos/laravel/ideas/issues/1173/labels{/name}","comments_url":"https://api.github.com/repos/laravel/ideas/issues/1173/comments","events_url":"https://api.github.com/repos/laravel/ideas/issues/1173/events","html_url":"https://github.com/laravel/ideas/issues/1173","id":324559145,"number":1173,"title":"[Proposal] Create Rule with more one parametrs for request validator","user":{"login":"attlantick","id":19490828,"avatar_url":"https://avatars2.githubusercontent.com/u/19490828?v=4","gravatar_id":"","url":"https://api.github.com/users/attlantick","html_url":"https://github.com/attlantick","followers_url":"https://api.github.com/users/attlantick/followers","following_url":"https://api.github.com/users/attlantick/following{/other_user}","gists_url":"https://api.github.com/users/attlantick/gists{/gist_id}","starred_url":"https://api.github.com/users/attlantick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/attlantick/subscriptions","organizations_url":"https://api.github.com/users/attlantick/orgs","repos_url":"https://api.github.com/users/attlantick/repos","events_url":"https://api.github.com/users/attlantick/events{/privacy}","received_events_url":"https://api.github.com/users/attlantick/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-18T21:35:55Z","updated_at":"2018-05-21T02:29:53Z","closed_at":null,"author_association":"NONE","body":"Hello. I had one problem before.\r\nNeeded create new required rule with more 1 parameter\r\n`new_required_if:take_off_client_cash,>,0`\r\nExample my request file:\r\n```php \r\n/**\r\n  * Class create check for enterprise\r\n  * @package App\\Http\\Requests\\enterprise\\single_enterprise\\check\r\n */\r\nuse App\\Http\\Requests\\BaseRequestValidator as Base; //My new base class for request\r\nclass Create extends Base\r\n    /**\r\n     * Get the validation rules that apply to the request.\r\n     * @return array\r\n     */\r\n    public function rules()\r\n    {\r\n        return [\r\n            'buyer_info' => 'required_with:rooms',\r\n            'buyer_info.id' => 'new_required_if:take_off_client_cash,>,0|numeric|nullable',\r\n            'buyer_info.phone' => ['string','nullable',new Phone()],\r\n           /*(_!_)*/\r\n            'take_off_client_cash' => 'nullable|numeric',\r\n            'comment'=>'nullable|string'\r\n        ];\r\n    }\r\n}\r\n```\r\nFor create this rule I cant use class with implements Rule and any others...\r\nFor make this rule i created new base class\r\n```php\r\n\r\nuse Illuminate\\Support\\Arr;\r\n\r\n/**\r\n * Every request validation class should extends this core class.\r\n *\r\n * Class BaseRequest\r\n * @package App\\Http\\Requests\r\n */\r\nclass BaseRequestValidator extends FormRequest\r\n{\r\n    /**\r\n     * Define form of api response.\r\n     *\r\n     * @param \\Illuminate\\Contracts\\Validation\\Validator|\\Illuminate\\Validation\\Validator $validator\r\n     */\r\n    public function withValidator($validator)\r\n    {\r\n        $validator->addImplicitExtension('new_required_if', function($attribute, $value, $parameters) use($validator)\r\n        {\r\n            $other = Arr::get($validator->getData(), $parameters[0]);\r\n            $operator = $parameters[1];\r\n            $values = array_slice($parameters, 2);\r\n\r\n            switch($operator){\r\n                case \">\":\r\n                    if ($other > $values[0]){\r\n                        return $validator->validateRequired($attribute, $value);\r\n                    }\r\n                    break;\r\n                case \"<\";\r\n                    if ($other < $values[0]){\r\n                        return $validator->validateRequired($attribute, $value);\r\n                    }\r\n                    break;\r\n                /*(_!_)*/\r\n                default:\r\n                    return false;\r\n            }\r\n\r\n            return true;\r\n        });\r\n\r\n    }\r\n}\r\n```\r\nCan you make this process easier (More understandable)\r\nSomething like ``` implements Rule ``` but interface must be with more parameters and used in Illuminate\\Validation\\Validator class in function validateAttribute"},"comment":{"url":"https://api.github.com/repos/laravel/ideas/issues/comments/390536825","html_url":"https://github.com/laravel/ideas/issues/1173#issuecomment-390536825","issue_url":"https://api.github.com/repos/laravel/ideas/issues/1173","id":390536825,"user":{"login":"ragingdave","id":1168344,"avatar_url":"https://avatars1.githubusercontent.com/u/1168344?v=4","gravatar_id":"","url":"https://api.github.com/users/ragingdave","html_url":"https://github.com/ragingdave","followers_url":"https://api.github.com/users/ragingdave/followers","following_url":"https://api.github.com/users/ragingdave/following{/other_user}","gists_url":"https://api.github.com/users/ragingdave/gists{/gist_id}","starred_url":"https://api.github.com/users/ragingdave/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ragingdave/subscriptions","organizations_url":"https://api.github.com/users/ragingdave/orgs","repos_url":"https://api.github.com/users/ragingdave/repos","events_url":"https://api.github.com/users/ragingdave/events{/privacy}","received_events_url":"https://api.github.com/users/ragingdave/received_events","type":"User","site_admin":false},"created_at":"2018-05-21T02:29:53Z","updated_at":"2018-05-21T02:29:53Z","author_association":"NONE","body":"I think this is actually a pretty good idea, in looking, the Rule contract seems to not have feature parity with other ways of adding custom rules. The ability to parameterize the Custom Rule seems like a no-brainer but would most likely be a 5.7 feature as the addition of a param would be a breaking change. I might take a stab at this if you haven't yet?"}}
{"actor":{"display_login":"ragingdave"}}