1. Go to this page and download the library: Download bitpress/blade-extensions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bitpress / blade-extensions example snippets
namespace App\Blade;
use BitPress\BladeExtension\Contracts\BladeExtension;
class CartExtension implements BladeExtension
{
public function getDirectives()
{
return [
'cartcount' => [$this, 'getCartCount']
];
}
public function getConditionals()
{
return [
'cartempty' => [$this, 'isCartEmpty']
];
}
public function getCartCount()
{
// logic to return cart count
}
public function isCartEmpty()
{
// logic for empty cart
}
}
use Illuminate\Support\ServiceProvider;
use BitPress\BladeExtension\Container\BladeRegistrar;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
BladeRegistrar::register(\App\Blade\CartExtension::class);
}
}
use \App\Blade\CartExtension::class;
BladeRegistrar::register(CartExtension::class, function () {
// Do stuff...
return new CartExtension($stuff);
});
public function register()
{
blade_extension(\App\Blade\CartExtension::class);
}