firstOrCreate( ['slug' => 'default'], ['name' => 'Default Workspace', 'slug' => 'default'], ); $tenant = Tenant::firstOrCreate([ 'tenant_id' => $seedTenantId, ], [ 'workspace_id' => (int) $workspace->getKey(), 'name' => 'Default Tenant', 'external_id' => (string) Str::uuid(), 'domain' => null, 'metadata' => [], ]); if ($tenant->workspace_id === null) { $tenant->forceFill([ 'workspace_id' => (int) $workspace->getKey(), ])->saveQuietly(); } $externalId = (string) ($tenant->external_id ?? ''); $isUuidV4 = Str::isUuid($externalId) && substr($externalId, 14, 1) === '4'; if (! $isUuidV4) { $tenant->forceFill([ 'external_id' => (string) Str::uuid(), ])->saveQuietly(); } $supported = config('tenantpilot.supported_policy_types', []); $now = now(); foreach ($supported as $index => $type) { $policyType = $type['type']; $platform = $type['platform'] ?? null; $externalId = 'seed-'.$policyType.'-'.($platform ?? 'any').'-'.$index; Policy::updateOrCreate( [ 'workspace_id' => (int) $workspace->getKey(), 'tenant_id' => $tenant->id, 'external_id' => $externalId, 'policy_type' => $policyType, ], [ 'workspace_id' => (int) $workspace->getKey(), 'display_name' => $type['label'] ?? ucfirst($policyType), 'platform' => $platform, 'last_synced_at' => $now, 'metadata' => ['seeded' => true], ] ); } } }