@@ -28,6 +28,12 @@ public function assert(MappingValue $mappingValue): bool
2828 */
2929 public function resolve (MappingValue $ mappingValue ): mixed
3030 {
31+ $ data = $ mappingValue ->data ;
32+
33+ if (is_string ($ data ) && str_contains ($ data , ', ' )) {
34+ $ data = array_filter (explode (', ' , $ data ));
35+ }
36+
3137 $ resolveModelAttributeReflector = $ mappingValue ->property ->getAttributes (ResolveModel::class);
3238
3339 /** @var \ReflectionAttribute<\OpenSoutheners\LaravelDto\Attributes\ResolveModel>|null $resolveModelAttributeReflector */
@@ -55,7 +61,7 @@ public function resolve(MappingValue $mappingValue): mixed
5561 ->toArray ();
5662
5763 if (is_array ($ modelType ) && $ mappingValue ->objectClass === Collection::class) {
58- $ valueClass = get_class ($ mappingValue -> data );
64+ $ valueClass = get_class ($ data );
5965
6066 $ modelType = $ modelClass [array_search ($ valueClass , $ modelClass )];
6167 }
@@ -66,33 +72,36 @@ public function resolve(MappingValue $mappingValue): mixed
6672 ) {
6773 $ modelType = $ resolveModelAttribute ->getMorphModel (
6874 $ mappingValue ->property ->getName (),
69- $ mappingValue ->class -> getProperties (ReflectionProperty:: IS_PUBLIC ) ,
75+ $ mappingValue ->allMappingData ,
7076 $ mappingValue ->types === Model::class ? [] : (array ) $ mappingValue ->types
7177 );
7278 }
7379
7480 if (! is_countable ($ modelType ) || count ($ modelType ) === 1 ) {
7581 return $ this ->resolveIntoModelInstance (
76- $ mappingValue -> data ,
82+ $ data ,
7783 ! is_countable ($ modelType ) ? $ modelType : $ modelType [0 ],
7884 $ mappingValue ->property ->getName (),
7985 $ modelWithAttributes ,
8086 $ resolveModelAttribute
8187 );
8288 }
8389
84- return Collection::make (array_map (
85- function (mixed $ valueA , mixed $ valueB ) use (&$ lastNonValue ): array {
86- if (! is_null ($ valueB )) {
87- $ lastNonValue = $ valueB ;
88- }
89-
90- return [$ valueA , $ valueB ?? $ lastNonValue ];
91- },
92- $ mappingValue ->data instanceof Collection ? $ mappingValue ->data ->all () : (array ) $ mappingValue ->data ,
93- (array ) $ modelType
94- ))->mapToGroups (fn (array $ value ) => [$ value [1 ] => $ value [0 ]])->flatMap (fn (Collection $ keys , string $ model ) => $ this ->resolveIntoModelInstance ($ keys , $ model , $ mappingValue ->property ->getName (), $ modelWithAttributes , $ resolveModelAttribute )
95- );
90+ return Collection::make (
91+ array_map (
92+ function (mixed $ valueA , mixed $ valueB ) use (&$ lastNonValue ): array {
93+ if (! is_null ($ valueB )) {
94+ $ lastNonValue = $ valueB ;
95+ }
96+
97+ return [$ valueA , $ valueB ?? $ lastNonValue ];
98+ },
99+ $ data ,
100+ (array ) $ modelType
101+ )
102+ )
103+ ->mapToGroups (fn (array $ value ) => [$ value [1 ] => $ value [0 ]])
104+ ->flatMap (fn (Collection $ keys , string $ model ) => $ this ->resolveIntoModelInstance ($ keys , $ model , $ mappingValue ->property ->getName (), $ modelWithAttributes , $ resolveModelAttribute ));
96105 }
97106
98107 /**
0 commit comments