From 19aaba8ccf5c224f4681a6c9f079b1ed4efffe0d Mon Sep 17 00:00:00 2001 From: Ihab Abou Afia Date: Tue, 7 May 2024 13:32:19 -0400 Subject: [PATCH] minor bug fixes --- README.md | 78 ++++++++++++++----- config/permissions-admin.php | 30 +++++-- resources/views/admin-navigation.blade.php | 32 ++++---- .../components/dynamic-classes.blade.php | 40 ++++++++++ .../components/forms/button-color.blade.php | 2 +- .../livewire/permission-component.blade.php | 2 +- .../views/livewire/role-component.blade.php | 2 +- src/Livewire/PermissionComponent.php | 1 + src/Livewire/RoleComponent.php | 1 + 9 files changed, 142 insertions(+), 46 deletions(-) create mode 100644 resources/views/components/dynamic-classes.blade.php diff --git a/README.md b/README.md index 451cc7c..dbdd0a2 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,15 @@ [![Total Downloads](https://img.shields.io/packagist/dt/ihabafia/permissions-admin.svg?style=flat-square)](https://packagist.org/packages/ihabafia/permissions-admin) This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. +This package is a cool livewire GUI for [Spatie Laravel Permission](https://github.com/spatie/laravel-permission) **(not included)**, and it will help you to: +- Create role. +- Create permission. +- Assign role to user. +- Give permission to role. +- Assign role to permission. +- Remove permission from role. -## Support us - -[](https://spatie.be/github-ad-click/permissions-admin) - -We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). - -We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). +All this via 3 livewire components that will show you the information in a dynamic table which is searchable, sortable and filtered. ## Installation @@ -23,24 +24,63 @@ You can install the package via composer: composer require ihabafia/permissions-admin ``` -You can publish and run the migrations with: - +### Additional Steps for installation +1. This package is depend on [Spatie Laravel Permission](https://github.com/spatie/laravel-permission), to install it if you didn't already: ```bash -php artisan vendor:publish --tag="permissions-admin-migrations" -php artisan migrate +composer require spatie/laravel-permission ``` - -You can publish the config file with: - +2. [Livewire](https://github.com/livewire/livewire) is required, to install it if you didn't already: ```bash -php artisan vendor:publish --tag="permissions-admin-config" +composer require livewire/livewire ``` +3. You need to create and empty ```App\Models\Role``` and ```App\Models\Permission``` class and add ```HasPermissionAdmin``` trait as follows: +```php +namespace App\Models; + +use IhabAfia\PermissionsAdmin\Traits\HasPermissionAdmin; +use Spatie\Permission\Models\Role as SpatieRole; + +class Role extends SpatieRole +{ + use HasPermissionAdmin; +} + +```` +```php +namespace App\Models; + +use IhabAfia\PermissionsAdmin\Traits\HasPermissionAdmin; +use Spatie\Permission\Models\Permission as SpatiePermission; + +class Permission extends SpatiePermission +{ + use HasPermissionAdmin; +} +```` +**These classes will not affect your application since these classes extends the original class.** + +4. You need to add ```HasPermissionAdmin``` trait in your ```User::class``` like follows: +```php +namespace App\Models; + +use IhabAfia\PermissionsAdmin\Traits\HasPermissionAdmin; -This is the contents of the published config file: +class User extends Authenticatable +{ + use HasPermissionAdmin; + ... +```` +This trait is needed for adding the search functionality to the 3 models. +5. Finally, you need to use this route in ```web.php``` ```php -return [ -]; +Route::rolesPermissionsAdmin(); +``` + +You might need to publish the config file to change routes with: + +```bash +php artisan vendor:publish --tag="permissions-admin-config" ``` Optionally, you can publish the views using @@ -59,7 +99,7 @@ echo $permissionsAdmin->echoPhrase('Hello, IhabAfia!'); ## Testing ```bash -composer test +Need Help ``` ## Changelog diff --git a/config/permissions-admin.php b/config/permissions-admin.php index 320be59..0302d32 100644 --- a/config/permissions-admin.php +++ b/config/permissions-admin.php @@ -5,24 +5,42 @@ */ return [ /* - * This is the route of your home application. + * This is the route of your home application for admins. */ - 'home' => 'admin.dashboard', + 'admin-home' => 'dashboard', + + /* + * This is the route of your home application for users (it can be the same as the above). + */ + 'user-home' => 'dashboard', + + /* + * This is the route of your user profile. + */ + 'user-profile' => 'user/profile', /* * In case you want to change the route of the user management route. */ - 'users_index' => 'admin.users', - 'users_management' => 'admin.users-management.index', + 'users-index' => 'users', /* * In case you want to change the route of the roles management route. */ - 'roles_index' => 'admin.roles', + 'roles-index' => 'roles', /* * In case you want to change the route of the permissions management route. */ - 'permissions_index' => 'admin.permissions', + 'permissions-index' => 'permissions', + + /* + * Using Gravatar in the Users list (Pending) + */ + 'use-gravatar' => false, + + /* + * The url to Gravatar website. (Pending) + */ 'gravatar_url' => 'https://www.gravatar.com/avatar/', ]; diff --git a/resources/views/admin-navigation.blade.php b/resources/views/admin-navigation.blade.php index de94e9c..84a049e 100644 --- a/resources/views/admin-navigation.blade.php +++ b/resources/views/admin-navigation.blade.php @@ -5,29 +5,25 @@
- @hasanyrole(['Super Admin', 'Admin']) - + - @endhasrole
@@ -47,20 +43,20 @@ - + {{ __('Profile') }} -
+ {{-- @csrf - {{ __('Log Out') }} -
+ --}}
@@ -81,11 +77,11 @@ diff --git a/resources/views/components/dynamic-classes.blade.php b/resources/views/components/dynamic-classes.blade.php new file mode 100644 index 0000000..88f3b9f --- /dev/null +++ b/resources/views/components/dynamic-classes.blade.php @@ -0,0 +1,40 @@ +
x
+
x
+
x
+ +x +x +x + +x +x +x + + + + diff --git a/resources/views/components/forms/button-color.blade.php b/resources/views/components/forms/button-color.blade.php index 224b78e..058c621 100644 --- a/resources/views/components/forms/button-color.blade.php +++ b/resources/views/components/forms/button-color.blade.php @@ -9,7 +9,7 @@ {{ $attributes }} {{ $attributes->merge(['class' => " font-medium text-center - text-sm px-5 py-[0.55rem] ml-3 + text-sm px-5 py-2 ml-3 rounded-lg border-2 focus:ring-2 focus:outline-none diff --git a/resources/views/livewire/permission-component.blade.php b/resources/views/livewire/permission-component.blade.php index 4b87d3b..497ec88 100644 --- a/resources/views/livewire/permission-component.blade.php +++ b/resources/views/livewire/permission-component.blade.php @@ -158,7 +158,7 @@ class="h-4 w-4 rounded border-gray-300 text-teal-600 focus:ring-teal-600" diff --git a/resources/views/livewire/role-component.blade.php b/resources/views/livewire/role-component.blade.php index 2323d29..3ac0447 100644 --- a/resources/views/livewire/role-component.blade.php +++ b/resources/views/livewire/role-component.blade.php @@ -158,7 +158,7 @@ class="h-4 w-4 rounded border-gray-300 text-teal-600 focus:ring-teal-600" diff --git a/src/Livewire/PermissionComponent.php b/src/Livewire/PermissionComponent.php index 46ebe5d..863d67a 100644 --- a/src/Livewire/PermissionComponent.php +++ b/src/Livewire/PermissionComponent.php @@ -112,6 +112,7 @@ public function updateRole(Role $role) public function editPermission(Permission $permission) { + $this->resetErrorBag(); $this->permissionForm->name = $permission->name; $this->permissionForm->roles = $permission->roles->pluck('name')->toArray(); diff --git a/src/Livewire/RoleComponent.php b/src/Livewire/RoleComponent.php index 4665383..15eea96 100644 --- a/src/Livewire/RoleComponent.php +++ b/src/Livewire/RoleComponent.php @@ -102,6 +102,7 @@ public function storeRole() public function editRole(Role $role) { + $this->resetErrorBag(); $this->roleForm->name = $role->name; $this->roleForm->permissions = $role->permissions->pluck('name')->toArray();