Posts

Showing posts with the label laravel blade

A Package for Laravel Blade Extension Classes

Image
Laravel created a Blade Extension package that allows you to register Blade extension classes in the service container that automatically get registered with the Blade compiler. You can also easily create new Blade extension classes with the provided  php artisan make:blade  command (auto-registered package commands FTW). Laravel Blade Extension Classes The concept isn’t revolutionary by any means, but user like how it organizes their project-specific blade extensions into service container classes. Let’s say, for example, that you have some custom directives around working with a shopping cart. Here’s a quick example of how it might look using Blade Extensions package: <?php namespace App \ Blade ; use BitPress \ BladeExtension \ Contracts \ BladeExtension ; class CartExtension implements BladeExtension { public function getDirectives () { return [ 'cartcount' => [ $this , 'getCartCount' ] ]; } ...