This is a recursive (read: inefficient) macro for Laravel's Collection that generates a list of all permutations of the values in a collection. I don't know of many cases in which one would need this, but who cares.
Note: Duplicate values in the original collection are not removed during permutation.
Collection::macro('permute', function () {
if ($this->isEmpty()) {
return new static([[]]);
}