Skip to content

Instantly share code, notes, and snippets.

@adamhut
Forked from calebporzio/RouteDirectives.php
Created January 5, 2020 03:18
Show Gist options
  • Save adamhut/4c9b3202e0d40aa674afc183ef1d778e to your computer and use it in GitHub Desktop.
Save adamhut/4c9b3202e0d40aa674afc183ef1d778e to your computer and use it in GitHub Desktop.
Blade Route Directives
<?php
// Register these inside a service provider:
Blade::directive('route', function ($expression) {
return "<?php echo route({$expression}) ?>";
});
Blade::directive('routeIs', function ($expression) {
return "<?php if (request()->routeIs({$expression})) : ?>";
});
Blade::directive('endrouteIs', function () {
return "<?php endif; ?>";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment