m2collective/laravel-view-directives

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

Maintainers

Package info

github.com/m2collective/laravel-view-directives

pkg:composer/m2collective/laravel-view-directives

Transparency log

Statistics

Installs: 1

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-07-24 06:46 UTC

This package is not auto-updated.

Last update: 2026-07-25 06:08:28 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-view-directives

The package will automatically register itself.

Usage

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

Create Directive

Creating a directive for displaying or formatting incoming arguments.

use M2Collective\ViewDirectives\Contracts\ClosingDirective;
use M2Collective\ViewDirectives\Contracts\LogicalDirective;
use M2Collective\ViewDirectives\Contracts\OpeningDirective;

final class Example implements OpeningDirective, LogicalDirective, ClosingDirective
{
    /**
     * @return string
     */
    public function openingTag(): string {
        return 'openingExample';
    }
    
    /**
     * @param mixed $expression
     * @return string
     */
    public function openingHandler(mixed $expression) : string
    {
        //...
    }
    
    /**
     * @return string
     */
    public function logicalTag(): string {
        return 'logicalExample';
    }
    
    /**
     * @param mixed $expression
     * @return string
     */
    public function logicalHandler(mixed $expression) : string
    {
        //...
    }
    
    /**
     * @return string
     */
    public function closingTag(): string {
        return 'closingExample';
    }
    
    /**
     * @param mixed $expression
     * @return string
     */
    public function closingHandler(mixed $expression) : string
    {
        //...
    }
}

Registering Directives

New directives are registered through the service provider.

use M2Collective\ViewDirectives\Providers\RegisterDirectives;

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

License

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