From 4f52e2d6874b344b006b82c9f20498ea31729cee Mon Sep 17 00:00:00 2001 From: Sang Nguyen Date: Wed, 3 Apr 2024 17:04:13 +0700 Subject: [PATCH] Registering customLabel macro once Form resolved --- .../FormBuilderServiceProvider.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Kris/LaravelFormBuilder/FormBuilderServiceProvider.php b/src/Kris/LaravelFormBuilder/FormBuilderServiceProvider.php index 4ae5b07b..ce37c84d 100644 --- a/src/Kris/LaravelFormBuilder/FormBuilderServiceProvider.php +++ b/src/Kris/LaravelFormBuilder/FormBuilderServiceProvider.php @@ -7,8 +7,8 @@ use Collective\Html\HtmlBuilder; use Illuminate\Support\ServiceProvider; use InvalidArgumentException; -use Kris\LaravelFormBuilder\Traits\ValidatesWhenResolved; use Kris\LaravelFormBuilder\Form; +use Kris\LaravelFormBuilder\Traits\ValidatesWhenResolved; class FormBuilderServiceProvider extends ServiceProvider { @@ -105,15 +105,15 @@ public function boot() __DIR__ . '/../../config/config.php' => config_path('laravel-form-builder.php') ]); - $form = $this->app[static::FORM_ABSTRACT]; - - $form->macro('customLabel', function($name, $value, $options = [], $escape_html = true) use ($form) { - if (isset($options['for']) && $for = $options['for']) { - unset($options['for']); - return $form->label($for, $value, $options, $escape_html); - } + $this->app->afterResolving(Form::class, function ($form) { + $form->macro('customLabel', function($name, $value, $options = [], $escape_html = true) use ($form) { + if (isset($options['for']) && $for = $options['for']) { + unset($options['for']); + return $form->label($for, $value, $options, $escape_html); + } - return $form->label($name, $value, $options, $escape_html); + return $form->label($name, $value, $options, $escape_html); + }); }); }