diff --git a/src/Console/InstallerTraits/CoreModules.php b/src/Console/InstallerTraits/CoreModules.php index d16d1dc..4205fa1 100644 --- a/src/Console/InstallerTraits/CoreModules.php +++ b/src/Console/InstallerTraits/CoreModules.php @@ -84,7 +84,9 @@ protected function migrateDatabase(): void protected function seedDatabase(): void { - (new Process([$this->phpBinary(), 'artisan', 'db:seed', '--class=Modules\User\Database\Seeders\UserSeeder'], base_path())) + copy(__DIR__.'/../../../stubs/database/seeders/DatabaseSeeder.php', base_path('database/seeders/DatabaseSeeder.php')); + + (new Process([$this->phpBinary(), 'artisan', 'db:seed'], base_path())) ->setTimeout(null) ->run(function ($type, $output) { $this->output->write($output); diff --git a/stubs/database/seeders/DatabaseSeeder.php b/stubs/database/seeders/DatabaseSeeder.php new file mode 100644 index 0000000..4c8f820 --- /dev/null +++ b/stubs/database/seeders/DatabaseSeeder.php @@ -0,0 +1,20 @@ +call([ + UserSeeder::class, + AclRoleSeeder::class, + AclPermissionSeeder::class, + AclModelHasRolesSeeder::class, + ]); + } +} diff --git a/stubs/modules/Acl/Database/Seeders/AclModelHasRolesSeeder.php b/stubs/modules/Acl/Database/Seeders/AclModelHasRolesSeeder.php new file mode 100644 index 0000000..c1fe445 --- /dev/null +++ b/stubs/modules/Acl/Database/Seeders/AclModelHasRolesSeeder.php @@ -0,0 +1,21 @@ +truncate(); + + //root + DB::table('model_has_roles')->insert([ + 'role_id' => 1, + 'model_type' => 'user', + 'model_id' => 1, + ]); + } +} diff --git a/stubs/modules/Acl/Database/Seeders/AclPermissionSeeder.php b/stubs/modules/Acl/Database/Seeders/AclPermissionSeeder.php new file mode 100644 index 0000000..72cabd3 --- /dev/null +++ b/stubs/modules/Acl/Database/Seeders/AclPermissionSeeder.php @@ -0,0 +1,58 @@ +getPermissions(); + + foreach ($permissions as $permission) { + Permission::create([ + 'name' => $permission, + 'guard_name' => 'user', + ]); + } + } + + private function getPermissions(): array + { + return [ + //Main Menu + 'Dashboard', + + //Acl: Access Control List + 'Acl', + 'Acl: User - List', + 'Acl: Permission - List', + 'Acl: Role - List', + + //User/UserIndex.vue + 'Acl: User - Manage Roles', + 'Acl: User - Manage Permissions', + 'Acl: User - Create', + 'Acl: User - Edit', + 'Acl: User - Delete', + + //AclPermission/PermissionIndex.vue + 'Acl: Permission - Create', + 'Acl: Permission - Edit', + 'Acl: Permission - Delete', + + //AclRole/RoleIndex.vue + 'Acl: Role - Create', + 'Acl: Role - Edit', + 'Acl: Role - Delete', + + //AclRolePermission/RolePermissionForm.vue + 'Acl: Role - Manage Permissions', + ]; + + } +} diff --git a/stubs/modules/Acl/Database/Seeders/AclRoleSeeder.php b/stubs/modules/Acl/Database/Seeders/AclRoleSeeder.php new file mode 100644 index 0000000..8769f67 --- /dev/null +++ b/stubs/modules/Acl/Database/Seeders/AclRoleSeeder.php @@ -0,0 +1,19 @@ + 'root', + 'guard_name' => 'user', + ]); + } +} diff --git a/stubs/modules/User/Database/Seeders/UserSeeder.php b/stubs/modules/User/Database/Seeders/UserSeeder.php index fa0945d..680e419 100644 --- a/stubs/modules/User/Database/Seeders/UserSeeder.php +++ b/stubs/modules/User/Database/Seeders/UserSeeder.php @@ -5,7 +5,6 @@ use Illuminate\Database\Seeder; use Illuminate\Support\Facades\Schema; use Modules\User\Models\User; -use Spatie\Permission\Models\Role; class UserSeeder extends Seeder { @@ -18,6 +17,7 @@ public function run() { Schema::disableForeignKeyConstraints(); + //this will be a root user... $testUser = User::factory()->create([ 'name' => 'Example User', 'email' => 'user@example.com', @@ -25,8 +25,6 @@ public function run() 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password ]); - Role::create(['name' => 'root']); - $testUser->assignRole('root'); Schema::enableForeignKeyConstraints();