{"action":"created","issue":{"url":"https://api.github.com/repos/spatie/laravel-permission/issues/130","repository_url":"https://api.github.com/repos/spatie/laravel-permission","labels_url":"https://api.github.com/repos/spatie/laravel-permission/issues/130/labels{/name}","comments_url":"https://api.github.com/repos/spatie/laravel-permission/issues/130/comments","events_url":"https://api.github.com/repos/spatie/laravel-permission/issues/130/events","html_url":"https://github.com/spatie/laravel-permission/issues/130","id":185428616,"number":130,"title":"Users where role = ?","user":{"login":"ScooterSam","id":4105581,"avatar_url":"https://avatars.githubusercontent.com/u/4105581?v=3","gravatar_id":"","url":"https://api.github.com/users/ScooterSam","html_url":"https://github.com/ScooterSam","followers_url":"https://api.github.com/users/ScooterSam/followers","following_url":"https://api.github.com/users/ScooterSam/following{/other_user}","gists_url":"https://api.github.com/users/ScooterSam/gists{/gist_id}","starred_url":"https://api.github.com/users/ScooterSam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ScooterSam/subscriptions","organizations_url":"https://api.github.com/users/ScooterSam/orgs","repos_url":"https://api.github.com/users/ScooterSam/repos","events_url":"https://api.github.com/users/ScooterSam/events{/privacy}","received_events_url":"https://api.github.com/users/ScooterSam/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-26T15:30:21Z","updated_at":"2016-12-14T16:00:22Z","closed_at":"2016-10-26T21:57:06Z","body":"First of all, amazing package. Super simple to use!\n\nI guess in theory you can hit the Roles table and grab all users where role = x\n\nBut it would be nice to have a function that does something like, User::whereRole('trial user')->all() for example.\n"},"comment":{"url":"https://api.github.com/repos/spatie/laravel-permission/issues/comments/267072820","html_url":"https://github.com/spatie/laravel-permission/issues/130#issuecomment-267072820","issue_url":"https://api.github.com/repos/spatie/laravel-permission/issues/130","id":267072820,"user":{"login":"jpmurray","id":1550428,"avatar_url":"https://avatars.githubusercontent.com/u/1550428?v=3","gravatar_id":"","url":"https://api.github.com/users/jpmurray","html_url":"https://github.com/jpmurray","followers_url":"https://api.github.com/users/jpmurray/followers","following_url":"https://api.github.com/users/jpmurray/following{/other_user}","gists_url":"https://api.github.com/users/jpmurray/gists{/gist_id}","starred_url":"https://api.github.com/users/jpmurray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpmurray/subscriptions","organizations_url":"https://api.github.com/users/jpmurray/orgs","repos_url":"https://api.github.com/users/jpmurray/repos","events_url":"https://api.github.com/users/jpmurray/events{/privacy}","received_events_url":"https://api.github.com/users/jpmurray/received_events","type":"User","site_admin":false},"created_at":"2016-12-14T16:00:22Z","updated_at":"2016-12-14T16:00:22Z","body":"Just to leave a trace, if anyone is looking for this, I couldn't make the code above from @freekmurze work, so I went on and checked the Laravel docs ;-)\r\n\r\nThis would work:\r\n\r\n```\r\nUser::whereHas('roles', function ($query) {\r\n    return $query->where('name', 'name-of-role');\r\n});\r\n```\r\n\r\nMy use case was that I needed to find the person holding the role \"owner\" on a certain model, so I went on and created an accessor on said model:\r\n\r\n```\r\npublic function getOwnerAttribute()\r\n    {\r\n        return $this->users()->whereHas('roles', function ($query) {\r\n            return $query->where('name', 'owner');\r\n        })->first();\r\n    }\r\n```\r\n\r\nSo also, thanks Freek, I actually never had a use case for whereHas before, now I'll probably use it everywhere I can! :D"}}
{"actor":{"display_login":"jpmurray"}}