0

Is it possible to get all permissions which are assigned to a specific role? Because in my Role and Permission Models are no relations defined and I don't know if its safe to add them by myself.

xTheWolf
  • 1,756
  • 4
  • 18
  • 43

1 Answers1

2

You have to assign the relations between your models in order to get permissions of a specific role

Role Class:

class Role extends EntrustRole{

    public function permissions(){
       return $this->belongsToMany(Permission::class);
    }

}

and now you can get all permissions related to a role like this:

 $user->load('roles.permissions');
 $permissions = $user->roles->first()->permissions;
Hossein Ahmadi
  • 839
  • 2
  • 11
  • 24