<?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
  ));
});