Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #61 from Kryptonit3/patch-1
Browse files Browse the repository at this point in the history
Make prefix selection automatic
  • Loading branch information
romanbican committed Jun 19, 2015
2 parents 5aaa00f + a4e1f74 commit f11c05d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
10 changes: 6 additions & 4 deletions src/Bican/Roles/Traits/HasRoleAndPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ public function level()
public function rolePermissions()
{
if (!$roles = $this->getRoles()->lists('id')->toArray()) { $roles = []; }

$prefix = config('database.connections.' . config('database.default') . '.prefix');

return Permission::select([config('roles.prefix') . 'permissions.*', config('roles.prefix') . 'permission_role.created_at as pivot_created_at', config('roles.prefix') . 'permission_role.updated_at as pivot_updated_at'])
->join(config('roles.prefix') . 'permission_role', config('roles.prefix') . 'permission_role.permission_id', '=', config('roles.prefix') . 'permissions.id')->join(config('roles.prefix') . 'roles', config('roles.prefix') . 'roles.id', '=', config('roles.prefix') . 'permission_role.role_id')
->whereIn(config('roles.prefix') . 'roles.id', $roles) ->orWhere(config('roles.prefix') . 'roles.level', '<', $this->level())
->groupBy(config('roles.prefix') . 'permissions.id');
return Permission::select([$prefix . 'permissions.*', $prefix . 'permission_role.created_at as pivot_created_at', $prefix . 'permission_role.updated_at as pivot_updated_at'])
->join($prefix . 'permission_role', $prefix . 'permission_role.permission_id', '=', $prefix . 'permissions.id')->join($prefix . 'roles', $prefix . 'roles.id', '=', $prefix . 'permission_role.role_id')
->whereIn($prefix . 'roles.id', $roles) ->orWhere($prefix . 'roles.level', '<', $this->level())
->groupBy($prefix . 'permissions.id');
}

/**
Expand Down
11 changes: 0 additions & 11 deletions src/config/roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@

'connection' => null,

/*
|--------------------------------------------------------------------------
| Database Table Prefix
|--------------------------------------------------------------------------
|
| If your tables have a prefix you may specify that here.
|
*/

'prefix' => '',

/*
|--------------------------------------------------------------------------
| Slug Separator
Expand Down

0 comments on commit f11c05d

Please sign in to comment.