route('destination.index'); } if (! $destination instanceof StandaloneDocker) { return redirect()->route('destination.show', ['destination_uuid' => $destination->uuid]); } $this->destination = $destination; $this->loadResources(); } catch (\Throwable $e) { return handleError($e, $this); } } /** * Load applications, services, and database resources deployed to the standalone Docker destination. * * @return void Populates the resources property for display. */ public function loadResources(): void { $this->resources = $this->collectResources([ $this->destination->applications, $this->destination->services, $this->destination->postgresqls, $this->destination->redis, $this->destination->mongodbs, $this->destination->mysqls, $this->destination->mariadbs, $this->destination->keydbs, $this->destination->dragonflies, $this->destination->clickhouses, ]); } /** * @param array> $groups * @return array */ protected function collectResources(array $groups): array { $rows = []; foreach ($groups as $group) { foreach ($group as $resource) { $rows[] = $this->resourceRow($resource); } } return $rows; } /** * @param Application|Service|StandalonePostgresql|StandaloneRedis|StandaloneMongodb|StandaloneMysql|StandaloneMariadb|StandaloneKeydb|StandaloneDragonfly|StandaloneClickhouse $resource * @return array{uuid:string,type:string,name:string,project:string|null,environment:string|null,url:string|null,search:string} */ protected function resourceRow(BaseModel $resource): array { $type = match (true) { $resource instanceof Application => 'application', $resource instanceof Service => 'service', default => 'database', }; $environment = $resource->environment; $project = $environment?->project; $routeName = "project.{$type}.configuration"; $url = ($project && $environment) ? route($routeName, [ 'project_uuid' => $project->uuid, 'environment_uuid' => $environment->uuid, "{$type}_uuid" => $resource->uuid, ]) : null; return [ 'uuid' => $resource->uuid, 'type' => $type, 'name' => $resource->name, 'project' => $project?->name, 'environment' => $environment?->name, 'url' => $url, 'search' => strtolower(implode(' ', array_filter([ $type, $resource->name, $project?->name, $environment?->name, ]))), ]; } public function render(): View { return view('livewire.destination.resources'); } }