*/ protected function collapseProps(): array { return $this->resource->propValues() ->with('prop') ->get() ->mapWithKeys(fn ($propValue): array => [ $propValue->tenant_prop_codigo => $this->normalizePropValue($propValue->value, $propValue->prop?->data_type?->value), ]) ->all(); } protected function normalizePropValue(mixed $value, ?string $dataType): mixed { return match ($dataType) { 'boolean' => filter_var($value, FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE) ?? $value, 'number' => is_numeric($value) ? $value + 0 : $value, default => $value, }; } /** * @return array */ public function toArray(Request $request): array { return [ 'id' => $this->id, 'codigo' => $this->codigo, 'nombre' => $this->nombre, 'dominio' => $this->dominio, 'props' => $this->collapseProps(), ]; } }