diff --git a/src/Commands/Show.php b/src/Commands/Show.php index 07223a385..3974da534 100644 --- a/src/Commands/Show.php +++ b/src/Commands/Show.php @@ -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'; @@ -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'); @@ -51,7 +55,7 @@ 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()]); }); @@ -59,7 +63,7 @@ public function handle() $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);