sudippalash / role-creator
Laravel Package for Role Management. This package uses the Spatie Laravel Permission package and includes role CRUD functionality & Seeder for permission.
Installs: 261
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Language:Blade
Requires
- php: ^7.3|^8.0
- laravel/framework: ^8.0|^9.0|^10.0|^11.0
- spatie/laravel-permission: ^6.0
README
role-creator
is a role management package of Laravel
that provides options to manage role for auth users.
Note: This package is wrapper of spatie/laravel-permission
package.
Install
Via Composer
composer require sudippalash/role-creator
Publish config, migrations & seeders files
You should publish
migrations files:
database/migrations/create_permission_tables.php
database/migrations/add_module_column_to_permissions_table.php
,
config files:
config/permission.php
,config/role-creator.php
and seeders file:
database/seeders/PermissionSeeder.php
with:
php artisan vendor:publish --provider="Sudip\RoleCreator\Providers\AppServiceProvider" --tag=required
For config/permission.php
file you should check spatie/laravel-permission
package documentation.
This is the contents of the published config file config/role-creator.php
:
return [ /* |-------------------------------------------------------------------------- | Extends Layout Name |-------------------------------------------------------------------------- | | Your main layout file path name. Example: layouts.app | */ 'layout_name' => 'layouts.app', /* |-------------------------------------------------------------------------- | Section Name |-------------------------------------------------------------------------- | | Your section name which in yield in main layout file. Example: content | */ 'section_name' => 'content', /* |-------------------------------------------------------------------------- | Route Name, Prefix & Middleware |-------------------------------------------------------------------------- | | Provide a route name for role route. Example: user.roles | Provide a prefix name for role url. Example: user/roles | If role route use any middleware then provide it or leave empty array. Example: ['auth'] */ 'route_name' => 'user.roles', 'route_prefix' => 'user/roles', 'middleware' => [], /* |-------------------------------------------------------------------------- | Role & Permission Name Pretty Print |-------------------------------------------------------------------------- | | You can set the delimiter to separate your role/permission name for pretty preview | Example: array('-', '_', '=', '|', '/') | */ 'role_permission_name_separator' => ['-', '_'], /* |-------------------------------------------------------------------------- | Auth Guard Name |-------------------------------------------------------------------------- | | Which authentication guard you use for role. Example: web or admin | */ 'auth_guard_name' => 'web', /* |-------------------------------------------------------------------------- | Role Prevent |-------------------------------------------------------------------------- | | Those role names hide from list and prevent from edit & delete. Example ['Super Admin'] | */ 'hide_role_names' => [], /* |-------------------------------------------------------------------------- | Bootstrap version |-------------------------------------------------------------------------- | | Which bootstrap you use in your application. Example: 3 or 4 or 5 | */ 'bootstrap_v' => 4, /* |-------------------------------------------------------------------------- | Flash Messages |-------------------------------------------------------------------------- | | After Save/Update flash message session key name | */ 'flash_success' => 'success', 'flash_error' => 'error', /* |-------------------------------------------------------------------------- | CSS |-------------------------------------------------------------------------- | | Add your css class in this property if you want to change design. */ 'css' => [ 'container' => null, 'card' => null, 'input' => null, 'btn' => null, 'table' => null, 'table_action_col_width' => null, 'table_action_btn' => null, ], ];
Optionally, you can publish the views using
php artisan vendor:publish --provider="Sudip\RoleCreator\Providers\AppServiceProvider" --tag=views
Optionally, you can publish the lang using
php artisan vendor:publish --provider="Sudip\RoleCreator\Providers\AppServiceProvider" --tag=lang
You should run the migrations with:
php artisan migrate
In database/seeders/PermissionSeeder.php
seed file you should set your permission data and then you should run the seed with:
php artisan db:seed --class=PermissionSeeder
Usage
You should copy the below line and paste in your project menu section
<a href="{{ route(config('role-creator.route_name').'.index') }}">{{ trans('role-creator::sp_role_creator.roles') }}</a>
Optional
If want to use this for multiple guard then you can use RoleCreator trait.
use Sudip\RoleCreator\Traits\RoleCrud; class YourController extends Controller { use RoleCrud; protected $guardName; protected $routeName; protected $hideRoles; public function __construct() { $this->guardName = '{your guard_name}'; $this->routeName = '{your resource route name}'; $this->hideRoles = '{if you want to hide any roles}'; } }