Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter users by role #47

Open
thujohn opened this issue Jul 3, 2015 · 3 comments
Open

Filter users by role #47

thujohn opened this issue Jul 3, 2015 · 3 comments

Comments

@thujohn
Copy link

thujohn commented Jul 3, 2015

Hi.

Have you planned to add a method to filter users by role ?

e.g. : User::role('admin')->get() or User::role('guest')->get()

@vluzrmos
Copy link
Member

vluzrmos commented Jul 3, 2015

cool. 👍

But I think it should have a nicer name, like User::whereRole('admin') or whereRoles(['admin', 'employ']).

Proposal:

1 - whereRoles, whereRole
2 - whichRole, whichRoles
3 - rolesAre(), roleIs()

@thujohn
Copy link
Author

thujohn commented Jul 3, 2015

Actually what I did is a simple scope :

public function scopeRole($query, $role)
{
    return $this->whereHas('roles', function($query) use($role){
        $query->where('name', $role);
    });
}

@vinicius73 vinicius73 added this to the 1.0 milestone Jul 8, 2015
@vinicius73 vinicius73 self-assigned this Jul 8, 2015
vinicius73 added a commit that referenced this issue Sep 14, 2015
```
User::WhichRoles(‘admin’)->get();
User::WhichRoles([‘admin’, ‘agent’])->get();
```
Issue #47
@vinicius73
Copy link
Member

Need apply tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants