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.
Via Composer
composer require sudippalash/role-creator
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
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>
use Sudip\RoleCreator\Traits\RoleCrud;
class YourController extends Controller
{
use RoleCrud;
protected $guardName, $routeName;
public function __construct()
{
$this->guardName = '{your new guard_name}';
$this->routeName = '{your resource route name}';
}
}