generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include default seeders in the installer.
- Loading branch information
1 parent
d6f8c87
commit 4cb419b
Showing
6 changed files
with
122 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Seeder; | ||
use Modules\Acl\Database\Seeders\AclModelHasRolesSeeder; | ||
use Modules\Acl\Database\Seeders\AclPermissionSeeder; | ||
use Modules\Acl\Database\Seeders\AclRoleSeeder; | ||
use Modules\User\Database\Seeders\UserSeeder; | ||
|
||
class DatabaseSeeder extends Seeder | ||
{ | ||
public function run(): void | ||
{ | ||
$this->call([ | ||
UserSeeder::class, | ||
AclRoleSeeder::class, | ||
AclPermissionSeeder::class, | ||
AclModelHasRolesSeeder::class, | ||
]); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
stubs/modules/Acl/Database/Seeders/AclModelHasRolesSeeder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Modules\Acl\Database\Seeders; | ||
|
||
use Illuminate\Database\Seeder; | ||
use Illuminate\Support\Facades\DB; | ||
|
||
class AclModelHasRolesSeeder extends Seeder | ||
{ | ||
public function run(): void | ||
{ | ||
DB::table('model_has_roles')->truncate(); | ||
|
||
//root | ||
DB::table('model_has_roles')->insert([ | ||
'role_id' => 1, | ||
'model_type' => 'user', | ||
'model_id' => 1, | ||
]); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
stubs/modules/Acl/Database/Seeders/AclPermissionSeeder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Modules\Acl\Database\Seeders; | ||
|
||
use Illuminate\Database\Seeder; | ||
use Spatie\Permission\Models\Permission; | ||
|
||
class AclPermissionSeeder extends Seeder | ||
{ | ||
public function run(): void | ||
{ | ||
Permission::truncate(); | ||
|
||
$permissions = $this->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', | ||
]; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Modules\Acl\Database\Seeders; | ||
|
||
use Illuminate\Database\Seeder; | ||
use Spatie\Permission\Models\Role; | ||
|
||
class AclRoleSeeder extends Seeder | ||
{ | ||
public function run(): void | ||
{ | ||
Role::truncate(); | ||
|
||
Role::create([ | ||
'name' => 'root', | ||
'guard_name' => 'user', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,15 +17,14 @@ public function run() | |
{ | ||
Schema::disableForeignKeyConstraints(); | ||
|
||
//this will be a root user... | ||
$testUser = User::factory()->create([ | ||
'name' => 'Example User', | ||
'email' => '[email protected]', | ||
'email_verified_at' => now(), | ||
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password | ||
]); | ||
|
||
Role::create(['name' => 'root']); | ||
|
||
$testUser->assignRole('root'); | ||
|
||
Schema::enableForeignKeyConstraints(); | ||
|