forgetCachedPermissions(); // Garante contexto GLOBAL (team = null) setPermissionsTeamId(null); /** * 1) CRIA ROLE GLOBAL super_admin (id_escola = NULL) * OBS: como você está com teams/id_escola, deixamos explícito. */ $role = Role::firstOrCreate([ 'name' => 'super_admin', 'guard_name' => 'web', 'id_escola' => null, ]); /** * 2) CRIA USUÁRIO SUPER ADMIN */ $user = User::firstOrCreate( ['email' => 'admin@admin.com'], [ 'name' => 'Super Admin', 'password' => bcrypt('123456'), 'is_super_admin' => true, 'current_escola_id' => null, ] ); /** * 3) ATRIBUI A ROLE (GLOBAL) AO USUÁRIO * Garante team = null novamente antes de gravar pivot. */ setPermissionsTeamId(null); $user->syncRoles([$role]); // Limpa cache de novo por segurança app(PermissionRegistrar::class)->forgetCachedPermissions(); $this->command->info('Super Admin + role super_admin criados e associados com sucesso!'); $this->command->info('Email: admin@admin.com'); $this->command->info('Senha: 123456'); } }