| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?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' => 256,
- 'children' => []
- ],
- [
- 'scope' => 'usuarios',
- 'description' => 'Usuários',
- 'descricao_detalhe' => 'Acesso aos Usuários',
- 'children' => []
- ],
- [
- 'scope' => 'processos',
- 'description' => 'Processos',
- 'bits' => 271,
- 'children' => [
- [
- 'scope' => 'processo_menu',
- 'description' => 'Menu de Processos',
- 'bits' => 271,
- ],
- [
- 'scope' => 'processo_relatorio_preliminar',
- 'description' => 'Relatório Preliminar',
- 'bits' => 271,
- ],
- [
- 'scope' => 'processo_acompanhamento_vistoria',
- 'description' => 'Acompanhamento de Vistoria',
- 'bits' => 271,
- ],
- // Add other child permissions here
- ]
- ]
- ];
- $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']);
- }
- }
- }
- }
|