Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Liam Hammett:
Laravel Blade Helpers
Dec 04, 2018 @ 15:20:36

Liam Hammett has written up a post to his site covering the use and creation of helpers for Laravel's Blade templating. He shows the use of a package he's created to help make using them with custom callbacks simpler.

Laravel’s Blade templating engine offers a ton of convenient directives you can use to make your view files beautiful and abstract anything that may be too complex or verbose to live inside HTML. It even gives a really handy way to add your own custom directives using the Blade::directive(…) method.

However, the callback in custom directives only receives a single parameter?—?the raw string expression from the view file. [...] As this seems to be the most common use case, I put together a package that attempts to help make these helper functions that little bit easier to define without the boilerplate of returning the string or having to consider what an expression may be when creating a directive.

In his package he introduces a new method that defines the name of the method and the name of the function to call. This second option can also be a custom callback function, making it even more flexible.

tagged: laravel blade template helper package custom callback tutorial

Link: https://medium.com/@liamhammett/laravel-blade-helpers-8d710fa31fd9


Trending Topics: