Skip to content

Commit

Permalink
Registering customLabel macro once Form resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
sangnguyenplus authored Apr 3, 2024
1 parent 916b83d commit 4f52e2d
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Kris/LaravelFormBuilder/FormBuilderServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
});
});
}

Expand Down

0 comments on commit 4f52e2d

Please sign in to comment.