Skip to content

Ihabafia/permissions-admin

Repository files navigation

This package for an admin of Spatie Laravel Permission package

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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 (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.

All this via 3 livewire components that will show you the information in a dynamic table which is searchable, sortable and filtered.

Installation

You can install the package via composer:

composer require ihabafia/permissions-admin

Additional Steps for installation

  1. This package is depend on Spatie Laravel Permission, to install it if you didn't already:
composer require spatie/laravel-permission
  1. Livewire is required, to install it if you didn't already:
composer require livewire/livewire 
  1. You need to create and empty App\Models\Role and App\Models\Permission class and add HasPermissionAdmin trait as follows:
namespace App\Models;

use IhabAfia\PermissionsAdmin\Traits\HasPermissionAdmin;
use Spatie\Permission\Models\Role as SpatieRole;

class Role extends SpatieRole
{
    use HasPermissionAdmin;
}
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.

  1. You need to add HasPermissionAdmin trait in your User::class like follows:
namespace App\Models;

use Spatie\Permission\Traits\HasRoles;
use IhabAfia\PermissionsAdmin\Traits\HasPermissionAdmin;

class User extends Authenticatable
{
    use HasRoles;
    use HasPermissionAdmin;
    ...
}

This trait is needed for adding the search functionality to the 3 models.

  1. Finally, you need to use this route in web.php
Route::rolesPermissionsAdmin();

You might need to publish the config file to change default routes with your own:

php artisan vendor:publish --tag="permissions-admin-config"

Optionally but recommended, you can publish the views using the command bellow, to make sure you get the correct styling of all the component.

php artisan vendor:publish --tag="permissions-admin-views"

Testing

Need Help

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.