'required', 'field.client_id' => 'required', 'field.value' => 'required', ])] public array $field = []; protected string $resourceName = 'client-api'; public function show(int|string $id): void { $this->id = $id; } public function hide(): void { $this->reset('mode'); } public function editMode(): void { $this->mode = 'update'; } #[Computed] public function endpoints(): array { $case = ApiType::cases(); $endpoints = []; $apiEndpoints = ApiEndpoint::all()->mapWithKeys(function ($item) { return [$item->key->value => $item]; }); $clients = $this->clients->pluck('ulid', 'id'); foreach ($case as $item) { $client_id = null; $value = null; if (isset($apiEndpoints[$item->value])) { $client_id = $apiEndpoints[$item->value]->client_id; $client_id = $clients[$client_id]; $value = $apiEndpoints[$item->value]->value; } $endpoints[$item->value] = [ 'label' => $item->label(), 'value' => $value, 'client_id' => $client_id, ]; } return $endpoints; } #[Computed] public function clients(): Collection { return Client::all(['id', 'ulid', 'name']); } public function save(AssignEndpointUrl $assign): void { $this->validate(); $assign->execute(new EndpointUrlDTO( clientId: $this->clients->where('ulid', $this->field['client_id'])->first()->id, endpointUrl: $this->field['value'], field: ApiType::tryFrom($this->field['type']) )); $this->mode = 'view'; $this->success($this->message()); } public function runSynchronization(ApiType $type, SynchronizeWithApi $api): void { try { $api->execute($type); $this->success(__('domains/channel/messages.clients.synced')); } catch (\Exception $e) { $this->error($e->getMessage()); } } };