Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jrdavidson's avatar

Sentinel Users and Roles

I'm trying to figure out how I can retrieve all users that belong to specific roles with Sentinel. I don't see a method on the users repository in the package that can accomplish this.

0 likes
2 replies
willvincent's avatar

The EloquentRole model has a relationship to users:

/**
     * The Users relationship.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function users()
    {
        return $this->belongsToMany(static::$usersModel, 'role_users', 'role_id', 'user_id')->withTimestamps();
    }

So if you load a role, you ought to be able to just call it's users() method to fetch all associated users

basherdesigns's avatar

What I've used in my controller:

    // Get all Admins

        $admins = Sentinel::findRoleBySlug('admin');
        $admins = $admins->users()->get();

Please or to participate in this conversation.