diff --git a/src/Directives/Directives.php b/src/Directives/Directives.php index c6c1989..d08e34b 100644 --- a/src/Directives/Directives.php +++ b/src/Directives/Directives.php @@ -14,12 +14,17 @@ abstract class Directives implements DirectivesContract */ protected bool $registered = false; + /** + * Directives to not load when a conflicting class exists. + */ + protected array $conflicts = []; + /** * Make an instance of the Directives. */ public static function make(): self { - return new static(); + return new static; } /** @@ -31,9 +36,13 @@ public function register(): void return; } - foreach ($this->directives() as $function => $directive) { - Blade::directive($function, $directive); - } + $conflicts = collect($this->conflicts) + ->filter(fn ($directives, $class) => class_exists($class)) + ->flatMap(fn ($directives) => (array) $directives); + + collect($this->directives()) + ->except($conflicts) + ->each(fn ($callback, $directive) => Blade::directive($directive, $callback)); $this->registered = true; } diff --git a/src/Directives/Helpers.php b/src/Directives/Helpers.php index 8a96db1..c1eefd9 100644 --- a/src/Directives/Helpers.php +++ b/src/Directives/Helpers.php @@ -6,6 +6,13 @@ class Helpers extends Directives { + /** + * Directives to not load when a conflicting class exists. + */ + protected array $conflicts = [ + 'Livewire\Livewire' => ['script', 'endscript', 'js'], + ]; + /** * The Helper directives. */