diff --git a/src/Traits/HasRoleAndPermission.php b/src/Traits/HasRoleAndPermission.php index 2f21e25..ff4276c 100755 --- a/src/Traits/HasRoleAndPermission.php +++ b/src/Traits/HasRoleAndPermission.php @@ -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) { @@ -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']); } } @@ -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(); } /**