Skip to content

Instantly share code, notes, and snippets.

@akoepcke
Forked from calebporzio/RouteDirectives.php
Created January 23, 2020 16:16
Show Gist options
  • Save akoepcke/ecadcaf3bf5f19a777983d23de2068d6 to your computer and use it in GitHub Desktop.
Save akoepcke/ecadcaf3bf5f19a777983d23de2068d6 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