Skip to content

Commit 62b0a63

Browse files
Registering customLabel macro only once Form service resolves (#725)
1 parent 916b83d commit 62b0a63

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/Kris/LaravelFormBuilder/FormBuilderServiceProvider.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Collective\Html\HtmlBuilder;
88
use Illuminate\Support\ServiceProvider;
99
use InvalidArgumentException;
10-
use Kris\LaravelFormBuilder\Traits\ValidatesWhenResolved;
1110
use Kris\LaravelFormBuilder\Form;
11+
use Kris\LaravelFormBuilder\Traits\ValidatesWhenResolved;
1212

1313
class FormBuilderServiceProvider extends ServiceProvider
1414
{
@@ -105,15 +105,15 @@ public function boot()
105105
__DIR__ . '/../../config/config.php' => config_path('laravel-form-builder.php')
106106
]);
107107

108-
$form = $this->app[static::FORM_ABSTRACT];
109-
110-
$form->macro('customLabel', function($name, $value, $options = [], $escape_html = true) use ($form) {
111-
if (isset($options['for']) && $for = $options['for']) {
112-
unset($options['for']);
113-
return $form->label($for, $value, $options, $escape_html);
114-
}
108+
$this->app->afterResolving(static::FORM_ABSTRACT, function (LaravelForm $form) {
109+
$form->macro('customLabel', function($name, $value, $options = [], $escapeHtml = true) use ($form) {
110+
if (isset($options['for']) && $for = $options['for']) {
111+
unset($options['for']);
112+
return $form->label($for, $value, $options, $escapeHtml);
113+
}
115114

116-
return $form->label($name, $value, $options, $escape_html);
115+
return $form->label($name, $value, $options, $escapeHtml);
116+
});
117117
});
118118
}
119119

0 commit comments

Comments
 (0)