L
L
lynnikvadim2016-10-10 04:16:58
Laravel
lynnikvadim, 2016-10-10 04:16:58

How to get users of the same role in Laravel?

How to get users of the User group only?

$users = User::with(['roles' => function ($query) {
            $query->where('name', '=', 'User');
            }])->paginate(50);           
            foreach ($users as $roles => $role) {
                $role->getRoles();
            }

With the help of this code I get all users. But only the role is assigned to users User.
Users of the "Admin" group do not receive a role.
What am I doing wrong ?
thank.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WebDev, 2016-10-10
@lynnikvadim

User::whereHas('roles', function($query) {
    $query->where('name', '=', 'User');
})->paginate(50);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question