Skip to content

Commit

Permalink
Fix Eloquent Strictness on permission:show Command (#2457)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 committed Jul 4, 2023
1 parent 3159b18 commit 7c74636
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Commands/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function handle()
{
$permissionClass = app(PermissionContract::class);
$roleClass = app(RoleContract::class);
$teamsEnabled = config('permission.teams');
$team_key = config('permission.column_names.team_foreign_key');

$style = $this->argument('style') ?? 'default';
Expand All @@ -36,11 +37,14 @@ public function handle()

$roles = $roleClass::whereGuardName($guard)
->with('permissions')
->when(config('permission.teams'), function ($q) use ($team_key) {
->when($teamsEnabled, function ($q) use ($team_key) {
$q->orderBy($team_key);
})
->orderBy('name')->get()->mapWithKeys(function ($role) use ($team_key) {
return [$role->name.'_'.($role->$team_key ?: '') => ['permissions' => $role->permissions->pluck('id'), $team_key => $role->$team_key]];
->orderBy('name')->get()->mapWithKeys(function ($role) use ($teamsEnabled, $team_key) {
return [$role->name.'_'.($teamsEnabled ? ($role->$team_key ?: '') : '') => [
'permissions' => $role->permissions->pluck('id'),
$team_key => $teamsEnabled ? $role->$team_key : null,
]];
});

$permissions = $permissionClass::whereGuardName($guard)->orderBy('name')->pluck('name', 'id');
Expand All @@ -51,15 +55,15 @@ public function handle()
})->prepend($permission);
});

if (config('permission.teams')) {
if ($teamsEnabled) {
$teams = $roles->groupBy($team_key)->values()->map(function ($group, $id) {
return new TableCell('Team ID: '.($id ?: 'NULL'), ['colspan' => $group->count()]);
});
}

$this->table(
array_merge([
config('permission.teams') ? $teams->prepend('')->toArray() : [],
isset($teams) ? $teams->prepend(new TableCell(''))->toArray() : [],
$roles->keys()->map(function ($val) {
$name = explode('_', $val);
array_pop($name);
Expand Down

0 comments on commit 7c74636

Please sign in to comment.