FareedR's avatar

list all users that has guard_name "api" spatie

how can i list all users that has guard name "api" . laravel return " There is no role named user. "

//packages used spatie permission

        $users = User::role('user')->get();

0 likes
2 replies
eliyas5044's avatar

@fareedr You may try these steps.

  1. First make sure, API guard present in your User model.
class User extends Authenticatable
{
    use Notifiable, HasRoles;

    /**
     * Default guard name for roles.
     *
     * @var string
     */
    protected $guard_name = 'api';
}
  1. There is a caching system of role, permission in this package. So clear you cache.
php artisan permission:cache-reset
// or
php artisan cache:clear
  1. Get user by role
$admins = User::role('admin')->get();

Let us know your feedback.

FareedR's avatar

so far it works . but im confused . how can superadmin ( web ) able to view all user ( api ) , you know what i mean ?

Please or to participate in this conversation.