Oct 24, 2019
2
Level 6
How does the Collection "unique" function work under the hood ?
So, I've noticed that you can pass a callback to the unique function from Laravel, like so:
From de docs: https://laravel.com/docs/5.8/collections#method-unique
$unique = $collection->unique(function ($item) {
return $item['brand'].$item['type'];
});
So it seems that you can basically concatenate the values of any combination of keys in your collection and it knows what to look for ?
Does it actually concatenate every combination until it finds a match ? I tried looking on the source code but couldn't figure it out.
Please or to participate in this conversation.