Created
December 14, 2019 16:04
-
-
Save peterfox/84c6e35310dbdd5f1ee98d4a1c3486d0 to your computer and use it in GitHub Desktop.
A Laravel Collection macro for prioritising certain attributes and then getting a unique set
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 | |
\Illuminate\Support\Collection::macro('prioritiseUnique', function ($unique, $proritise) { | |
return $this->sortByDesc($proritise) | |
->unique($unique) | |
->values(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment