| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace Database\Seeders;
- use App\DataTransferObjects\PermissionDto;
- use Illuminate\Database\Seeder;
- use App\Services\PermissionService;
- class PermissionSeeder extends Seeder
- {
- public function __construct(
- protected PermissionService $permissionService,
- ) {
- }
- public function run()
- {
- // Criação de Permissões
- /*
- visualizar = 1
- adicionar = 2
- editar = 4
- deletar = 8
- imprimir = 16
- exportar = 32
- importar = 64
- limitar = 128
- menu = 256
- para cada cada bit selecionado se faz a soma dos valores.
- */
- $permissions = [
- [
- 'scope' => 'dashboard',
- 'description' => 'Dashboard',
- 'bits' => 511,
- 'children' => []
- ],
- [
- 'scope' => 'usuarios',
- 'description' => 'Usuários',
- 'bits' => 271,
- 'children' => []
- ],
- ];
- $this->createPermissionsAndChildren($permissions);
- $this->command->info('Permissions seeded successfully.');
- }
- private function createPermissionsAndChildren(array $permissions)
- {
- foreach ($permissions as $permission) {
- $this->permissionService->store(PermissionDto::fromArray($permission));
- if (isset($permission['children'])) {
- $this->createPermissionsAndChildren($permission['children']);
- }
- }
- }
- }
|