Skip to content

Commit

Permalink
same with hydrate
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Dec 14, 2023
1 parent 173a546 commit d0296a2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Synths/DataCollectionSynth.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,19 @@ public function dehydrate(DataCollection $target, $dehydrateChild)
];
}

public function hydrate($value, $meta)
/**
* @param array<mixed> $value
* @param array<string, class-string> $meta
* @param mixed $hydrateChild
* @return \Spatie\LaravelData\DataCollection
*/
public function hydrate($value, $meta, $hydrateChild)
{
return new DataCollection($meta['class'], $value);
foreach ($value as $key => $child) {
$value[$key] = $hydrateChild($key, $child);
}

return $meta['class']::make($value);
}

public function get(&$target, $key)
Expand Down

0 comments on commit d0296a2

Please sign in to comment.