xTheWolf
xTheWolf

Reputation: 1886

Laravel Entrust -> get all Permissions for a role?

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.

Upvotes: 0

Views: 1745

Answers (1)

Hossein Ahmadi
Hossein Ahmadi

Reputation: 849

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;

Upvotes: 2

Related Questions