Skip to content

Commit

Permalink
Register components lazily (#136)
Browse files Browse the repository at this point in the history
* Register components lazily

* Remove unused imports
  • Loading branch information
mabdullahsari committed Sep 20, 2024
1 parent 5d60695 commit 5772783
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/HoneypotServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 "<?php echo view('honeypot::honeypotFormFields'); ?>";
$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 () => "<?php echo view('honeypot::honeypotFormFields'); ?>");
});
}
}

0 comments on commit 5772783

Please sign in to comment.