From 4bca8152c64942bcef58a1acd636e1bf78b36136 Mon Sep 17 00:00:00 2001 From: "Leandro G. Gehlen" Date: Thu, 30 Jul 2020 08:28:37 -0300 Subject: [PATCH 1/2] Respect permission class customizations --- src/Nova/Role.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Nova/Role.php b/src/Nova/Role.php index 73d35f8..6ae5895 100644 --- a/src/Nova/Role.php +++ b/src/Nova/Role.php @@ -11,7 +11,6 @@ use Laravel\Nova\Fields\MorphToMany; use Eminiarts\NovaPermissions\Checkboxes; use Eminiarts\NovaPermissions\Role as RoleModel; -use Spatie\Permission\Models\Permission as SpatiePermission; class Role extends Resource { @@ -77,6 +76,7 @@ public function fields(Request $request) return [$key => $key]; }); + $permissionClass = config('permission.models.permission'); $userResource = Nova::resourceForModel(getModelForGuard($this->guard_name)); return [ @@ -97,13 +97,16 @@ public function fields(Request $request) return $request->user()->isSuperAdmin(); }) , - Checkboxes::make(__('Permissions'), 'prepared_permissions')->withGroups()->options(SpatiePermission::all()->map(function ($permission, $key) { - return [ - 'group' => __(ucfirst($permission->group)), - 'option' => $permission->name, - 'label' => __($permission->name), - ]; - })->groupBy('group')->toArray()) + Checkboxes::make(__('Permissions'), 'prepared_permissions') + ->withGroups() + ->options($permissionClass::all()->map(function ($permission, $key) { + return [ + 'group' => __(ucfirst($permission->group)), + 'option' => $permission->name, + 'label' => __($permission->name), + ]; + }) + ->groupBy('group')->toArray()) , Text::make(__('Users'), function () { return count($this->users); From fb4cb3fa5e719f1b44a7ed2ba0dd4487c7be71f6 Mon Sep 17 00:00:00 2001 From: "Leandro G. Gehlen" Date: Thu, 30 Jul 2020 08:31:49 -0300 Subject: [PATCH 2/2] Code style --- src/Nova/Role.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Nova/Role.php b/src/Nova/Role.php index 6ae5895..1e3ba06 100644 --- a/src/Nova/Role.php +++ b/src/Nova/Role.php @@ -106,8 +106,9 @@ public function fields(Request $request) 'label' => __($permission->name), ]; }) - ->groupBy('group')->toArray()) - , + ->groupBy('group') + ->toArray()), + Text::make(__('Users'), function () { return count($this->users); })->exceptOnForms(),