laravel-acl
laravel-acl copied to clipboard
get roles by id
Hi,
Are you able to add a method getRolesById() to return the role ids rather than slugs?
Thanks
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.