@@ -13,17 +13,17 @@ trait LoopFunctions
1313 /**
1414 * Choose proper strategy to loop over the data.
1515 *
16- * @param Model|array|null $data
17- * @param mixed|null $rescue
16+ * @param Model|\ArrayAccess| array|null $data
17+ * @param mixed|null $rescue
1818 *
1919 * @return void
2020 */
21- public function propertiesFrom (Model |array |null $ data = null , mixed $ rescue = null ): void
21+ public function propertiesFrom (Model |\ ArrayAccess | array |null $ data = null , mixed $ rescue = null ): void
2222 {
2323 if ($ data ) {
2424 match (true ) {
25- is_array ($ data ) => $ this ->arrayToProperties ($ data , $ rescue ),
2625 $ data instanceof Model => $ this ->attributesToProperties ($ data , $ rescue ),
26+ default => $ this ->arrayToProperties ($ data , $ rescue ),
2727 };
2828 }
2929 }
@@ -52,15 +52,21 @@ public function attributesToProperties(?Model $model = null, mixed $rescue = nul
5252 /**
5353 * Map array data to class properties.
5454 *
55- * @param array|null $data
56- * @param mixed|null $rescue
55+ * @param array|\ArrayAccess| null $data
56+ * @param mixed|null $rescue
5757 *
5858 * @return void
5959 */
60- public function arrayToProperties (? array $ data , mixed $ rescue = null ): void
60+ public function arrayToProperties (array | \ ArrayAccess | null $ data , mixed $ rescue = null ): void
6161 {
6262 collect ($ data ?? [])
6363 ->except ($ this ->ignoredPropertyNames ())
64- ->each (fn ($ value , $ key ) => $ this ->assignValue ($ key , $ value , $ rescue ));
64+ ->each (function ($ value , $ key ) use ($ rescue ) {
65+ if ($ this ->canWalkRecursively ($ value )) {
66+ $ this ->propertiesFrom ($ value , $ rescue );
67+ }
68+
69+ $ this ->assignValue ($ key , $ value , $ rescue );
70+ });
6571 }
6672}
0 commit comments