m2collective/laravel-blade-directive

Maintainers

Package info

github.com/m2collective/laravel-blade-directive

pkg:composer/m2collective/laravel-blade-directive

Statistics

Installs: 1

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-06-17 12:12 UTC

This package is not auto-updated.

Last update: 2026-06-17 18:45:35 UTC


README

This package simplifies and systematizes the creation and registration of user directives.

Laravel PHP

Installation

You can install the package via composer:

composer require m2collective/laravel-blade-directive

The package will automatically register itself.

Usage

By installing the package, you can create and register directives in a simpler and more intuitive way.

Default Directive

Creating a simple directive for displaying or formatting incoming arguments.

use M2Collective\BladeDirective\DefaultBladeDirective;

final class Example implements DefaultBladeDirective
{
    /**
     * @return string
     */
    public function tag(): string {
        return 'example';
    }
    
    /**
     * @param mixed $expression
     * @return string
     */
    public function handler(mixed $expression) : string
    {
        //...
    }
}

Logical Directive

Creating a logical directive that satisfies certain conditions.

use M2Collective\BladeDirective\LogicalBladeDirective;

final class Example implements DefaultBladeDirective
{
    /**
     * @return string
     */
    public function openingTag(): string {
        return 'example';
    }
    
    /**
     * @param mixed $expression
     * @return string
     */
    public function openingHandler(mixed $expression) : string
    {
        //...
    }
    
    /**
     * @return string
     */
    public function elseTag(): string {
        return 'elseExample';
    }
    
    /**
     * @param mixed $expression
     * @return string
     */
    public function elseHandler(mixed $expression) : string
    {
        //...
    }
    
    /**
     * @return string
     */
    public function closingTag(): string {
        return 'endExample';
    }
    
    /**
     * @param mixed $expression
     * @return string
     */
    public function closingHandler(mixed $expression) : string
    {
        //...
    }
}

Registering Directives

New directives are registered through the service provider.

use M2Collective\BladeDirective\Concerns\RegisterBladeDirectives;

final class ExampleServiceProvider extends ServiceProvider
{
    use RegisterBladeDirectives;
    
    /**
     * @return void
     */
    public function boot(): void
    {
        $this->registerBladeDirective(
            new ExampleDirective()
        );
        
        // or
        
        $this->registerBladeDirectives([
            new ExampleDirective(),
            //...
        ]);
    }
}

License

The MIT License (MIT). Please see the License file for more information.