Skip to content

Commit

Permalink
Merge pull request #164 from tmali16/patch-1
Browse files Browse the repository at this point in the history
custom table name error
  • Loading branch information
jeremykenedy authored Nov 24, 2021
2 parents 3699591 + 36a5632 commit bcdfd7d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Traits/HasRoleAndPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public function level()
public function rolePermissions()
{
$permissionModel = app(config('roles.models.permission'));
$permissionTable = config('roles.permissionsTable');
$roleTable = config('roles.rolesTable');

if (!$permissionModel instanceof Model) {
Expand All @@ -201,19 +202,19 @@ public function rolePermissions()

if (config('roles.inheritance')) {
return $permissionModel
::select(['permissions.*', 'permission_role.created_at as pivot_created_at', 'permission_role.updated_at as pivot_updated_at'])
->join('permission_role', 'permission_role.permission_id', '=', 'permissions.id')
::select([$permissionTable . '.*', 'permission_role.created_at as pivot_created_at', 'permission_role.updated_at as pivot_updated_at'])
->join('permission_role', 'permission_role.permission_id', '=', $permissionTable .'.id')
->join($roleTable, $roleTable.'.id', '=', 'permission_role.role_id')
->whereIn($roleTable.'.id', $this->getRoles()->pluck('id')->toArray())
->orWhere($roleTable.'.level', '<', $this->level())
->groupBy(['permissions.id', 'permissions.name', 'permissions.slug', 'permissions.description', 'permissions.model', 'permissions.created_at', 'permissions.updated_at', 'permissions.deleted_at', 'pivot_created_at', 'pivot_updated_at']);
->groupBy([$permissionTable . '.id', $permissionTable .'.name', $permissionTable .'.slug', $permissionTable .'.description', $permissionTable .'.model', $permissionTable .'.created_at', 'permissions.updated_at', $permissionTable .'.deleted_at', 'pivot_created_at', 'pivot_updated_at']);
} else {
return $permissionModel
::select(['permissions.*', 'permission_role.created_at as pivot_created_at', 'permission_role.updated_at as pivot_updated_at'])
->join('permission_role', 'permission_role.permission_id', '=', 'permissions.id')
::select([$permissionTable .'.*', 'permission_role.created_at as pivot_created_at', 'permission_role.updated_at as pivot_updated_at'])
->join('permission_role', 'permission_role.permission_id', '=', $permissionTable .'.id')
->join($roleTable, $roleTable.'.id', '=', 'permission_role.role_id')
->whereIn($roleTable.'.id', $this->getRoles()->pluck('id')->toArray())
->groupBy(['permissions.id', 'permissions.name', 'permissions.slug', 'permissions.description', 'permissions.model', 'permissions.created_at', 'permissions.updated_at', 'permissions.deleted_at', 'pivot_created_at', 'pivot_updated_at']);
->groupBy([$permissionTable . '.id', $permissionTable .'.name', $permissionTable .'.slug', $permissionTable .'.description', $permissionTable .'.model', $permissionTable .'.created_at', $permissionTable .'.updated_at', $permissionTable .'.deleted_at', 'pivot_created_at', 'pivot_updated_at']);
}
}

Expand All @@ -224,7 +225,7 @@ public function rolePermissions()
*/
public function userPermissions()
{
return $this->belongsToMany(config('roles.models.permission'))->withTimestamps();
return $this->belongsToMany(config('roles.models.permission'), config('permissionsUserTable'))->withTimestamps();
}

/**
Expand Down

0 comments on commit bcdfd7d

Please sign in to comment.