Skip to content

Instantly share code, notes, and snippets.

@calebporzio
Created January 4, 2020 10:33
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save calebporzio/03d610c813d6639e96accc3b06892242 to your computer and use it in GitHub Desktop.
Save calebporzio/03d610c813d6639e96accc3b06892242 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; ?>";
});
@markvaneijk
Copy link

You’re right, I wrote it too quickly 😅

@matijakovacevic
Copy link

Copy pasted it, and wondered why it didn't work 😅
(felt like 2000's when I was doing it the same aka script kiddie style)

didn't know of the IF directive though, so thanks for pointing it out! 🤓

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