*/ public function toArray(Request $request): array { $this->resource->loadMissing(['fields', 'sections']); $visibleFields = $this->fields ->filter(fn ($f) => (bool) $f->is_portal_visible && ! (bool) $f->is_admin_only) ->values(); return [ 'id' => $this->id, 'name' => $this->name, 'slug' => $this->slug, 'purpose' => $this->purpose instanceof \BackedEnum ? $this->purpose->value : $this->purpose, 'description' => $this->description, 'locale' => $this->locale, 'consent_version' => $this->consent_version, 'submission_deadline' => optional($this->submission_deadline)->toIso8601String(), 'section_level_submit' => (bool) $this->section_level_submit, 'sections' => $this->sections->map(fn ($s) => [ 'id' => $s->id, 'slug' => $s->slug, 'name' => $s->name, 'description' => $s->description, 'sort_order' => (int) $s->sort_order, ])->values()->all(), 'fields' => $visibleFields->map(fn ($f) => [ 'id' => $f->id, 'slug' => $f->slug, 'field_type' => $f->field_type, 'label' => $f->label, 'help_text' => $f->help_text, 'options' => is_array($f->options) ? array_values($f->options) : null, 'validation_rules' => $f->validation_rules, 'is_required' => (bool) $f->is_required, 'display_width' => $f->display_width instanceof \BackedEnum ? $f->display_width->value : $f->display_width, 'conditional_logic' => $f->conditional_logic, 'sort_order' => (int) $f->sort_order, 'form_schema_section_id' => $f->form_schema_section_id, ])->values()->all(), ]; } }