Skip to content

Instantly share code, notes, and snippets.

@harikt
Last active September 17, 2017 19:04
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 harikt/b5596b5d0aade1ab32afc162ebe82538 to your computer and use it in GitHub Desktop.
Save harikt/b5596b5d0aade1ab32afc162ebe82538 to your computer and use it in GitHub Desktop.
How can we extend Blade ?
I am using the directive https://laravel.com/docs/5.5/blade#extending-blade
@url('article_show', ['id' => '3'], ['foo' => 'bar'], 'fragment')
Problem is the rest of the params after string `'article_show'` is not received on call back.
I am trying to do something similar to : https://zendframework.github.io/zend-expressive/features/template/twig/
{{ path('article_show', {'id': '3'}) }}
which generates: /article/3
$urlHelperFactory = new UrlHelperFactory();
$urlHelper = $urlHelperFactory($container);
$viewResolver->resolve('blade')->getCompiler()->directive('url', function (
$routeName = null,
array $routeParams = [],
array $queryParams = [],
$fragmentIdentifier = null,
array $options = []
) use ($urlHelper) {
// this works fine
return $urlHelper->generate('article_show', ['id' => '3'], ['foo' => 'bar'], 'fragment');
// this breaks for the params are not received as expected.
// return $urlHelper->generate($routeName, $routeParams, $queryParams, $fragmentIdentifier, $options);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment