laravel-acl icon indicating copy to clipboard operation
laravel-acl copied to clipboard

get roles by id

Open mybigman opened this issue 9 years ago • 1 comments

Hi,

Are you able to add a method getRolesById() to return the role ids rather than slugs?

Thanks

mybigman avatar Mar 29 '16 06:03 mybigman

Try this:

array_keys($your_model->getRoles())

This works for me in the User model:

    public function getRoleIdsAttribute($value)
    {
        // getRoles() will return [role_id => role_slug, ...]
        return array_keys($this->getRoles());
    }

In my admin forms I can use $user->role_ids to bind to checkboxes to turn roles on and off.

judgej avatar Sep 01 '16 11:09 judgej