$propValues * @return array */ public static function collapsed(iterable $propValues): array { return collect($propValues) ->mapWithKeys(fn (ModelPropValue $propValue) => [ $propValue->prop->codigo => $propValue->value, ]) ->all(); } /** * @return array */ public static function collapsedFromPropable(object $model): array { if (! in_array(Propable::class, class_uses_recursive($model), true)) { throw new InvalidArgumentException('The given model must use the Propable trait.'); } return static::collapsed( $model->propValues()->with('prop')->get(), ); } /** * @return array */ public function toArray(Request $request): array { return [$this->prop->codigo => $this->value]; } }