Skip to content

Instantly share code, notes, and snippets.

@peterfox
Created December 14, 2019 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterfox/84c6e35310dbdd5f1ee98d4a1c3486d0 to your computer and use it in GitHub Desktop.
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
<?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