Created
November 1, 2017 19:53
-
-
Save abdumu/1d7486dec4d86be78d1ab3a29db7e2a9 to your computer and use it in GitHub Desktop.
Laravel multidimensional Collection diff function as a macro (you can add it at AppServiceProvider.php boot method)
This file contains 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 | |
/* | |
* Get the diff between two collections | |
* | |
* @param Illuminate\Support\Collection|array $items | |
* | |
* @return static | |
*/ | |
Collection::macro('mdiff', function($items){ | |
return new static($this->filter(function($item) use ($items){ | |
return Collection::wrap($items)->filter(function($a) use ($item){ | |
return $a === $item; | |
})->isEmpty(); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing it was the thing that I was finding for hours this script saved me. Thanks brother