Skip to content

Instantly share code, notes, and snippets.

@elishaukpong
Created May 1, 2022 23:29
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 elishaukpong/e3a1b4379267433a438414c843740481 to your computer and use it in GitHub Desktop.
Save elishaukpong/e3a1b4379267433a438414c843740481 to your computer and use it in GitHub Desktop.
Simple example of DRY
/** BEFORE DRY */
<a href="{{route(sprintf('%s.templateLibrary.index', app()->getLocale()))}">Hello</a>
<a href="{{route(sprintf('%s.templateLibrary.index', app()->getLocale()))}">Hello 2</a>
<a href="{{route(sprintf('%s.templateLibrary.index', app()->getLocale()))}">Hello 3</a>
/** AFTER DRY */
function getRouteString($route){
return route(sprintf("%s.{$route}", app()->getLocale()));
}
<a href="{{getRouteString('templateLibrary.index')}}">Hello</a>
<a href="{{getRouteString('templateLibrary.index')}}">Hello 2</a>
<a href="{{getRouteString('templateLibrary.index')}}">Hello 3</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment