Skip to content

Instantly share code, notes, and snippets.

@dakota
Created June 22, 2016 14:13
Show Gist options
  • Save dakota/cbfa036e0f0927372ff728b81cdeedf4 to your computer and use it in GitHub Desktop.
Save dakota/cbfa036e0f0927372ff728b81cdeedf4 to your computer and use it in GitHub Desktop.
$property = $options['propertyPath'];
$propertyPath = explode('.', $property);
$query->formatResults(function ($results) use ($formatters, $property, $propertyPath) {
$extracted = [];
foreach ($results as $result) {
foreach ($propertyPath as $propertyPathItem) {
$result = $result[$propertyPathItem];
}
$extracted[] = $result;
}
$extracted = new Collection($extracted);
foreach ($formatters as $callable) {
$extracted = new ResultSetDecorator($callable($extracted));
}
return $results->insert($property, $extracted);
}, Query::PREPEND);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment