clientId = $clientId; $this->client = Client::findOrFail($clientId); $this->primaryId = $this->client->contacts() ->wherePivot('is_primary', true) ->first()?->id; Flux::modal('set-primary-contact')->show(); } #[Computed] public function clientContacts() { if (!$this->client) { return collect(); } return $this->client->contacts() ->orderBy('last_name') ->orderBy('first_name') ->get(); } public function save(): void { if (!$this->primaryId) { return; } // Clear existing primary $this->client->contacts()->wherePivot('is_primary', true) ->each(fn ($contact) => $this->client->contacts()->updateExistingPivot( $contact->id, ['is_primary' => false] )); // Set new primary $this->client->contacts()->updateExistingPivot( $this->primaryId, ['is_primary' => true] ); $this->reset(['clientId', 'client', 'primaryId']); Flux::modal('set-primary-contact')->close(); $this->dispatch('client-updated'); } }; ?>