Skip to content

Instantly share code, notes, and snippets.

@minedun6
Created December 3, 2018 10:54
Show Gist options
  • Save minedun6/1d8609f2e44c4371fdc9c246a8dc25e4 to your computer and use it in GitHub Desktop.
Save minedun6/1d8609f2e44c4371fdc9c246a8dc25e4 to your computer and use it in GitHub Desktop.
Laravel "some" macro
<?php
Collection::macro('some', function ($callback) {
return !! $this->first(function ($value, $key) use ($callback) {
return $callback($value, $key);
});
});
// use case
collect([1, 2, 3, 4])->some(function ($value) {
return $value > 2;
}); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment