> */ public array $choicesSearchable = []; public function selectAllChoice(string $key): void { $field = $this->resolveChoiceField($key); data_set($this, $field->formPath, ($field->allIds)()); $this->searchChoice($key); $field->after?->__invoke(); } protected function resolveChoiceField(string $key): ChoiceField { return $this->choiceFields()[$key] ?? throw new InvalidArgumentException("Unknown choice field [{$key}]."); } /** @return array */ abstract protected function choiceFields(): array; /** * @param string $key this should be one of the top level array key, defined in choiceFields() * @param string $value this is the value to search for */ public function searchChoice(string $key, string $value = ''): void { $field = $this->resolveChoiceField($key); $this->choicesSearchable[$key] = ($field->search)($value); } public function clearChoice(string $key): void { $field = $this->resolveChoiceField($key); data_set($this, $field->formPath, []); $field->after?->__invoke(); } }