{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/9959","labels_url":"https://api.github.com/repos/laravel/framework/issues/9959/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/9959/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/9959/events","html_url":"https://github.com/laravel/framework/pull/9959","id":101366138,"number":9959,"title":"[5.2] Add dynamic array input support on Validator","user":{"login":"antonybudianto","id":7658554,"avatar_url":"https://avatars.githubusercontent.com/u/7658554?v=3","gravatar_id":"","url":"https://api.github.com/users/antonybudianto","html_url":"https://github.com/antonybudianto","followers_url":"https://api.github.com/users/antonybudianto/followers","following_url":"https://api.github.com/users/antonybudianto/following{/other_user}","gists_url":"https://api.github.com/users/antonybudianto/gists{/gist_id}","starred_url":"https://api.github.com/users/antonybudianto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antonybudianto/subscriptions","organizations_url":"https://api.github.com/users/antonybudianto/orgs","repos_url":"https://api.github.com/users/antonybudianto/repos","events_url":"https://api.github.com/users/antonybudianto/events{/privacy}","received_events_url":"https://api.github.com/users/antonybudianto/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-17T08:15:00Z","updated_at":"2015-08-17T08:42:06Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/9959","html_url":"https://github.com/laravel/framework/pull/9959","diff_url":"https://github.com/laravel/framework/pull/9959.diff","patch_url":"https://github.com/laravel/framework/pull/9959.patch"},"body":"Hi guys, I have a proposal.\r\nI had a case where I had to validate an input array with Validator, and normally we validate it like this:\r\n```php\r\npublic function rules()\r\n{\r\n  $rules = [\r\n    'itemname.0 ' => ' required',\r\n    'itemname.1' => 'required',\r\n    ...\r\n  ];\r\n\r\n  return $rules;\r\n}\r\n```\r\nand so on, and if the input is **dynamic**, we can use loop like this:\r\n```php\r\npublic function rules()\r\n{\r\n  $rules = [\r\n    'name' => 'required|max:255',\r\n  ];\r\n\r\n  foreach($this->request->get('items') as $key => $val)\r\n  {\r\n    $rules['items.'.$key] = 'required|max:10';\r\n  }\r\n\r\n  return $rules;\r\n}\r\n\r\n```\r\n\r\nThis PR enables us to only write it as follows:\r\n```php\r\npublic function rules()\r\n{\r\n        return [\r\n            'food[]' => 'required|min:3',\r\n            'drink[]' => 'required',\r\n            'name' => 'required',\r\n        ];\r\n}\r\n\r\n```\r\nIf it's approved, then I will write the test case and squash, if no, then it's okay.\r\nPS: If the code can still be improved, then please help!\r\n\r\nThank you."},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/131732835","html_url":"https://github.com/laravel/framework/pull/9959#issuecomment-131732835","issue_url":"https://api.github.com/repos/laravel/framework/issues/9959","id":131732835,"user":{"login":"antonybudianto","id":7658554,"avatar_url":"https://avatars.githubusercontent.com/u/7658554?v=3","gravatar_id":"","url":"https://api.github.com/users/antonybudianto","html_url":"https://github.com/antonybudianto","followers_url":"https://api.github.com/users/antonybudianto/followers","following_url":"https://api.github.com/users/antonybudianto/following{/other_user}","gists_url":"https://api.github.com/users/antonybudianto/gists{/gist_id}","starred_url":"https://api.github.com/users/antonybudianto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/antonybudianto/subscriptions","organizations_url":"https://api.github.com/users/antonybudianto/orgs","repos_url":"https://api.github.com/users/antonybudianto/repos","events_url":"https://api.github.com/users/antonybudianto/events{/privacy}","received_events_url":"https://api.github.com/users/antonybudianto/received_events","type":"User","site_admin":false},"created_at":"2015-08-17T08:42:06Z","updated_at":"2015-08-17T08:42:06Z","body":"Thanks @GrahamCampbell  for the guides"}}