Skip to content

Instantly share code, notes, and snippets.

@martinbean
Created July 30, 2016 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinbean/2712815d649c2c95a3cc87e46ac75e3e to your computer and use it in GitHub Desktop.
Save martinbean/2712815d649c2c95a3cc87e46ac75e3e to your computer and use it in GitHub Desktop.
Laravel Request startsWith and endsWith macros
<?php
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Str;
Request::macro('startsWith', function () {
return Str::startsWith(func_get_args());
});
Request::macro('endsWith', function () {
return Str::endsWith(func_get_args());
});
<?php
$isNewsSection = Request::startsWith('news');
$isRssRequest = Request::endsWith('.rss');
@martinbean
Copy link
Author

martinbean commented Jul 30, 2016

You can add these macros to a service provider.

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