Laravel-permission: how to get all users belong to same role?

Created on 30 Nov 2017  路  2Comments  路  Source: spatie/laravel-permission

hi,
i meet some trouble, now i want to query all users of superAdmin,

roleName = 'superAdmin', so what should I do ?

Most helpful comment

Not directly in the document but is in the source.

$superAdmin = Role::findByName('superAdmin');
dd($superAdmin->users);

Of course, that's a Collection so things like...

$superAdmin->users->each(function($user)
{
    dump($user->name);
});

Behave nicely too. :)

All 2 comments

Not directly in the document but is in the source.

$superAdmin = Role::findByName('superAdmin');
dd($superAdmin->users);

Of course, that's a Collection so things like...

$superAdmin->users->each(function($user)
{
    dump($user->name);
});

Behave nicely too. :)

Anything QueryBuilder instead of Collection?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NattananWs picture NattananWs  路  3Comments

ergonomicus picture ergonomicus  路  3Comments

hosseinnedaei picture hosseinnedaei  路  3Comments

younus93 picture younus93  路  4Comments

vpratfr picture vpratfr  路  4Comments