In Zizaco/entrust's Laravel Entrust, how do you setup the Entrust class relationships with Eloquent so you can get the list of permissions a role has like so:
// get admin role
$adminRole = Role::find(1);
// get the permission of the admin role
$adminRolePermissions = $adminRole->permissions();
I've tried adding the following Eloquent relationships to the Role
class:
class Role class {
public function permissions()
{
return $this->hasManyThrough('App\Permission', 'App\PermissionRole', 'role_id', 'permission_id');
}
}
With this, when I get an instance of a role and try to get its permissions like so:
$adminRolePermissions = $adminRole->permission();
this error occurs:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'permission_role.id' in 'on clause' (SQL: select
permissions
.*,permission_role
.role_id
frompermissions
inner joinpermission_roles
onpermission_role
.id
=permissions
.permission_id
wherepermission_role
.role_id
= 1)
Of course, I have already created the following models: PermissionRole
for the permission_role
table.