From 57727836997ae7351a4f56008bbaf4e2801ce4a0 Mon Sep 17 00:00:00 2001 From: Muhammed Sari Date: Fri, 20 Sep 2024 15:45:00 +0200 Subject: [PATCH] Register components lazily (#136) * Register components lazily * Remove unused imports --- src/HoneypotServiceProvider.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/HoneypotServiceProvider.php b/src/HoneypotServiceProvider.php index 776c499..11a3b10 100644 --- a/src/HoneypotServiceProvider.php +++ b/src/HoneypotServiceProvider.php @@ -2,8 +2,8 @@ namespace Spatie\Honeypot; -use Illuminate\Support\Facades\Blade; -use Illuminate\Support\Facades\View; +use Illuminate\Contracts\View\Factory; +use Illuminate\View\Compilers\BladeCompiler; use Spatie\Honeypot\SpamResponder\SpamResponder; use Spatie\Honeypot\View\HoneypotComponent; use Spatie\Honeypot\View\HoneypotViewComposer; @@ -38,14 +38,15 @@ protected function registerBindings(): self return $this; } - protected function registerBladeClasses(): self + protected function registerBladeClasses(): void { - View::composer('honeypot::honeypotFormFields', HoneypotViewComposer::class); - Blade::component('honeypot', HoneypotComponent::class); - Blade::directive('honeypot', function () { - return ""; + $this->callAfterResolving('view', static function (Factory $view) { + $view->composer('honeypot::honeypotFormFields', HoneypotViewComposer::class); }); - return $this; + $this->callAfterResolving('blade.compiler', static function (BladeCompiler $blade) { + $blade->component('honeypot', HoneypotComponent::class); + $blade->directive('honeypot', static fn () => ""); + }); } }