diff --git a/src/Synths/DataCollectionSynth.php b/src/Synths/DataCollectionSynth.php new file mode 100644 index 000000000..c4591eb58 --- /dev/null +++ b/src/Synths/DataCollectionSynth.php @@ -0,0 +1,55 @@ +all(); + + foreach ($data as $key => $child) { + $data[$key] = $dehydrateChild($key, $child); + } + + return [ + $data, + ['class' => get_class($target)], + ]; + } + + /** + * @param array $value + * @param array $meta + * @param mixed $hydrateChild + * @return \Spatie\LaravelData\DataCollection + */ + public function hydrate($value, $meta, $hydrateChild) + { + foreach ($value as $key => $child) { + $value[$key] = $hydrateChild($key, $child); + } + + return $meta['class']::make($value); + } + + public function get(&$target, $key) + { + return $target[$key] ?? null; + } + + public function set(&$target, $key, $value) + { + $target[$key] = $value; + } +}