Skip to content

Instantly share code, notes, and snippets.

@abdumu
Created November 1, 2017 19:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdumu/1d7486dec4d86be78d1ab3a29db7e2a9 to your computer and use it in GitHub Desktop.
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)
<?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();
}));
});
@bhaveshdaswani93
Copy link

Thanks for sharing it was the thing that I was finding for hours this script saved me. Thanks brother

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment