{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/21721","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/21721/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/21721/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/21721/events","html_url":"https://github.com/laravel/framework/issues/21721","id":266295898,"number":21721,"title":"Global Scope for Unique validation rule.","user":{"login":"Aferz","id":8954655,"avatar_url":"https://avatars0.githubusercontent.com/u/8954655?v=4","gravatar_id":"","url":"https://api.github.com/users/Aferz","html_url":"https://github.com/Aferz","followers_url":"https://api.github.com/users/Aferz/followers","following_url":"https://api.github.com/users/Aferz/following{/other_user}","gists_url":"https://api.github.com/users/Aferz/gists{/gist_id}","starred_url":"https://api.github.com/users/Aferz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aferz/subscriptions","organizations_url":"https://api.github.com/users/Aferz/orgs","repos_url":"https://api.github.com/users/Aferz/repos","events_url":"https://api.github.com/users/Aferz/events{/privacy}","received_events_url":"https://api.github.com/users/Aferz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-10-17T22:09:46Z","updated_at":"2017-10-18T04:17:03Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"- Laravel Version: 5.5.17\r\n- PHP Version: 7.1\r\n- Database Driver & Version: Mysql 5.7\r\n\r\n### Description:\r\n\r\nGlobal scopes are not being applied in built in Laravel rules.\r\n\r\n### Steps To Reproduce:\r\n\r\n1. Apply a global scope to any model:\r\n\r\n```php\r\n...\r\n\r\nclass Course extends Model\r\n{\r\n    ...\r\n\r\n    protected static function boot()\r\n    {\r\n        parent::boot();\r\n        \r\n        static::addGlobalScope('center_id', function ($query) {\r\n            $query->where('courses.center_id', 1);\r\n        });\r\n    }\r\n\r\n    ...\r\n}\r\n\r\n...\r\n```\r\n\r\n2. Validate dummy data:\r\n\r\n```php\r\n$this->validate(request(), [\r\n    'class' => [\r\n        'required',\r\n        Rule::unique('courses', 'class')\r\n    ]\r\n]);\r\n```\r\n\r\n\r\n3. Check executed query:\r\n\r\n```php\r\n[\r\n    \"query\" => \"select count(*) as aggregate from \"courses\" where \"class\" = ?\"\r\n    \"bindings\" => array:1 [\r\n        0 => \"dummy_data\"\r\n    ]\r\n    \"time\" => 0.12\r\n]\r\n```\r\n\r\nAs you can see, the global scope is not being applied to the \"unique\" rule query. I didn't test it, but other rules could have the same problem.\r\n\r\nIs this expected behaviour ?\r\n\r\nThanks !"},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/337455957","html_url":"https://github.com/laravel/framework/issues/21721#issuecomment-337455957","issue_url":"https://api.github.com/repos/laravel/framework/issues/21721","id":337455957,"user":{"login":"devcircus","id":18542852,"avatar_url":"https://avatars3.githubusercontent.com/u/18542852?v=4","gravatar_id":"","url":"https://api.github.com/users/devcircus","html_url":"https://github.com/devcircus","followers_url":"https://api.github.com/users/devcircus/followers","following_url":"https://api.github.com/users/devcircus/following{/other_user}","gists_url":"https://api.github.com/users/devcircus/gists{/gist_id}","starred_url":"https://api.github.com/users/devcircus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devcircus/subscriptions","organizations_url":"https://api.github.com/users/devcircus/orgs","repos_url":"https://api.github.com/users/devcircus/repos","events_url":"https://api.github.com/users/devcircus/events{/privacy}","received_events_url":"https://api.github.com/users/devcircus/received_events","type":"User","site_admin":false},"created_at":"2017-10-18T04:17:03Z","updated_at":"2017-10-18T04:17:03Z","author_association":"CONTRIBUTOR","body":"e.g. soft deletes utilizes global scope. You can't run a unique validation check while ignoring some rows."}}
{"actor":{"display_login":"devcircus"}}