m2collective / laravel-view-directives
This package simplifies and systematizes the creation and registration of user directives.
Package info
github.com/m2collective/laravel-view-directives
pkg:composer/m2collective/laravel-view-directives
Requires
- php: ^8.3
- laravel/framework: ^13.0
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.
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.