Skip to content

Instantly share code, notes, and snippets.

@kevinruscoe
Last active June 14, 2020 10:54
Show Gist options
  • Save kevinruscoe/c8092be648021540773285a176e563b4 to your computer and use it in GitHub Desktop.
Save kevinruscoe/c8092be648021540773285a176e563b4 to your computer and use it in GitHub Desktop.
A few handy response macros
<?php
Request::macro('startsWith', function(string $needle) {
return collect(array_filter(
$this->all(),
fn($key) => str_starts_with($key, $needle),
ARRAY_FILTER_USE_KEY
));
});
Request::macro('endsWith', function(string $needle) {
return collect(array_filter(
$this->all(),
fn($key) => str_ends_with($key, $needle),
ARRAY_FILTER_USE_KEY
));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment