R renamed config & files
This commit is contained in:
parent
19f4b8a220
commit
7ddd3491e1
|
|
@ -8,7 +8,6 @@ return [
|
|||
'role_permission' => \Blax\Roles\Models\RolePermission::class,
|
||||
'permission' => \Blax\Roles\Models\Permission::class,
|
||||
'permission_usage' => \Blax\Roles\Models\PermissionUsage::class,
|
||||
|
||||
],
|
||||
|
||||
'table_names' => [
|
||||
|
|
@ -14,7 +14,7 @@ return new class extends Migration
|
|||
public function up(): void
|
||||
{
|
||||
// Permission
|
||||
Schema::create(config('permissions.table_names.permissions'), function (Blueprint $table) {
|
||||
Schema::create(config('roles.table_names.permissions'), function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->string('description')->nullable();
|
||||
|
|
@ -22,7 +22,7 @@ return new class extends Migration
|
|||
});
|
||||
|
||||
// PermissionUsage
|
||||
Schema::create(config('permissions.table_names.permission_usage'), function (Blueprint $table) {
|
||||
Schema::create(config('roles.table_names.permission_usage'), function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('permission_id')->constrained('permissions')->onDelete('cascade');
|
||||
$table->morphs('user');
|
||||
|
|
@ -31,7 +31,7 @@ return new class extends Migration
|
|||
});
|
||||
|
||||
// Role
|
||||
Schema::create(config('permissions.table_names.roles'), function (Blueprint $table) {
|
||||
Schema::create(config('roles.table_names.roles'), function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('parent_id')
|
||||
->nullable()
|
||||
|
|
@ -44,7 +44,7 @@ return new class extends Migration
|
|||
});
|
||||
|
||||
// RoleMember
|
||||
Schema::create(config('permissions.table_names.role_members'), function (Blueprint $table) {
|
||||
Schema::create(config('roles.table_names.role_members'), function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('role_id')->constrained('roles')->onDelete('cascade');
|
||||
$table->morphs('member');
|
||||
|
|
@ -54,7 +54,7 @@ return new class extends Migration
|
|||
});
|
||||
|
||||
// RolePermission
|
||||
Schema::create(config('permissions.table_names.role_permission'), function (Blueprint $table) {
|
||||
Schema::create(config('roles.table_names.role_permission'), function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('role_id')->constrained('roles')->onDelete('cascade');
|
||||
$table->foreignId('permission_id')->constrained('permissions')->onDelete('cascade');
|
||||
|
|
@ -69,6 +69,10 @@ return new class extends Migration
|
|||
*/
|
||||
public function down(): void
|
||||
{
|
||||
//
|
||||
Schema::dropIfExists(config('roles.table_names.role_permission'));
|
||||
Schema::dropIfExists(config('roles.table_names.role_members'));
|
||||
Schema::dropIfExists(config('roles.table_names.roles'));
|
||||
Schema::dropIfExists(config('roles.table_names.permission_usage'));
|
||||
Schema::dropIfExists(config('roles.table_names.permissions'));
|
||||
}
|
||||
};
|
||||
|
|
@ -15,7 +15,7 @@ class Permission extends Model {
|
|||
{
|
||||
parent::__construct($attributes);
|
||||
|
||||
$this->table = config('permissions.table_names.permissions') ?: parent::getTable();
|
||||
$this->table = config('roles.table_names.permissions') ?: parent::getTable();
|
||||
}
|
||||
|
||||
public function usages()
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class PermissionUsage extends Model {
|
|||
{
|
||||
parent::__construct($attributes);
|
||||
|
||||
$this->table = config('permissions.table_names.permission_usages') ?: parent::getTable();
|
||||
$this->table = config('roles.table_names.permission_usages') ?: parent::getTable();
|
||||
}
|
||||
|
||||
public function permission()
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class Role extends Model {
|
|||
{
|
||||
parent::__construct($attributes);
|
||||
|
||||
$this->table = config('permissions.table_names.roles') ?: parent::getTable();
|
||||
$this->table = config('roles.table_names.roles') ?: parent::getTable();
|
||||
}
|
||||
|
||||
public function members() {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class RoleMember extends Model {
|
|||
{
|
||||
parent::__construct($attributes);
|
||||
|
||||
$this->table = config('permissions.table_names.role_members') ?: parent::getTable();
|
||||
$this->table = config('roles.table_names.role_members') ?: parent::getTable();
|
||||
}
|
||||
|
||||
public function role() {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class RolePermission extends Model {
|
|||
{
|
||||
parent::__construct($attributes);
|
||||
|
||||
$this->table = config('permissions.table_names.role_permission') ?: parent::getTable();
|
||||
$this->table = config('roles.table_names.role_permission') ?: parent::getTable();
|
||||
}
|
||||
|
||||
public function role() {
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ class PermissionsServiceProvider extends \Illuminate\Support\ServiceProvider
|
|||
*/
|
||||
public function register()
|
||||
{
|
||||
$this->offerPublishing();
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -22,7 +21,9 @@ class PermissionsServiceProvider extends \Illuminate\Support\ServiceProvider
|
|||
*/
|
||||
public function boot()
|
||||
{
|
||||
// Load routes, migrations, etc. if needed
|
||||
$this->offerPublishing();
|
||||
|
||||
$this->registerModelBindings();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -42,11 +43,20 @@ class PermissionsServiceProvider extends \Illuminate\Support\ServiceProvider
|
|||
}
|
||||
|
||||
$this->publishes([
|
||||
__DIR__.'/../config/permission.php' => config_path('permission.php'),
|
||||
], 'permission-config');
|
||||
__DIR__.'/../config/roles.php' => config_path('roles.php'),
|
||||
], 'roles-config');
|
||||
|
||||
$this->publishes([
|
||||
__DIR__.'/../database/migrations/create_permission_tables.php.stub' => $this->getMigrationFileName('create_permission_tables.php'),
|
||||
], 'permission-migrations');
|
||||
__DIR__.'/../database/migrations/create_blax_role_tables.php.stub' => $this->getMigrationFileName('create_blax_role_tables.php'),
|
||||
], 'roles-migrations');
|
||||
}
|
||||
|
||||
protected function registerModelBindings(): void
|
||||
{
|
||||
$this->app->bind(\Blax\Roles\Models\Role::class, fn ($app) => $app->make($app->config['roles.models.role']));
|
||||
$this->app->bind(\Blax\Roles\Models\RoleMember::class, fn ($app) => $app->make($app->config['roles.models.role_member']));
|
||||
$this->app->bind(\Blax\Roles\Models\RolePermission::class, fn ($app) => $app->make($app->config['roles.models.role_permission']));
|
||||
$this->app->bind(\Blax\Roles\Models\Permission::class, fn ($app) => $app->make($app->config['roles.models.permission']));
|
||||
$this->app->bind(\Blax\Roles\Models\PermissionUsage::class, fn ($app) => $app->make($app->config['roles.models.permission_usage']));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ trait HasRoles
|
|||
public function roles()
|
||||
{
|
||||
return $this->morphToMany(
|
||||
config('permissions.models.role', \Blax\Roles\Models\Role::class),
|
||||
config('roles.models.role', \Blax\Roles\Models\Role::class),
|
||||
'member',
|
||||
config('permissions.table_names.role_members', 'role_members')
|
||||
config('roles.table_names.role_members', 'role_members')
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue