Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Just some useful macros for Laravel Collections
<?php
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
/**
* Remove items whose keys contain certain strings.
*/
Collection::macro('rejectKeysWith', function (array|string $needles) {
return $this->reject(function ($value, $key) use ($needles) {
return Str::of($key)->contains($needles);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment