Created
March 13, 2018 12:18
-
-
Save jsdecena/5928e8c9892555704e93096b6c4401c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$attributes = $productAttributes | |
->pluck('attributesValues') | |
->flatten() | |
->unique() | |
->groupBy(function (AttributeValue $av) { | |
return $av->attribute->name; | |
}) | |
->map(function (Collection $collection) { | |
return $collection->map(function (AttributeValue $av) { | |
return $av->value; | |
})->unique(); | |
}) | |
->all(); | |
dump($attributes); | |
// returns | |
array:2 [▼ | |
"Color" => Collection {#574 ▼ | |
#items: array:2 [▼ | |
0 => "red" | |
6 => "blue" | |
] | |
} | |
"Size" => Collection {#565 ▼ | |
#items: array:3 [▼ | |
0 => "small" | |
1 => "medium" | |
2 => "large" | |
] | |
} | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment