From 115e5b32f67a0501f328c14bcfebd30f45a02844 Mon Sep 17 00:00:00 2001 From: Kyrch Date: Tue, 9 Jul 2024 15:41:09 -0300 Subject: [PATCH] fix(filament): added create option using (#714) --- app/Filament/Components/Fields/BelongsTo.php | 3 +++ app/Filament/Resources/Wiki/Anime/Theme.php | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Filament/Components/Fields/BelongsTo.php b/app/Filament/Components/Fields/BelongsTo.php index f485e1fe0..8d5afbefd 100644 --- a/app/Filament/Components/Fields/BelongsTo.php +++ b/app/Filament/Components/Fields/BelongsTo.php @@ -27,8 +27,11 @@ class BelongsTo extends ComponentsSelect */ protected function reload(): void { + $model = $this->resource->getModel(); + if ($this->showCreateOption && $this->resource !== null) { $this->createOptionForm(fn (Form $form) => $this->resource::form($form)->getComponents()); + $this->createOptionUsing(fn (array $data) => (new $model)::query()->create($data)->getKey()); } if ($this->resource) { diff --git a/app/Filament/Resources/Wiki/Anime/Theme.php b/app/Filament/Resources/Wiki/Anime/Theme.php index e3bd87e99..6a10103af 100644 --- a/app/Filament/Resources/Wiki/Anime/Theme.php +++ b/app/Filament/Resources/Wiki/Anime/Theme.php @@ -232,8 +232,7 @@ class Theme extends BaseResource ->resource(ArtistResource::class) ->showCreateOption() ->required() - ->rules(['required']) - ->createOptionUsing(fn (array $data) => Artist::query()->create($data)->getKey()), + ->rules(['required']), TextInput::make(ArtistSong::ATTRIBUTE_AS) ->label(__('filament.fields.artist.songs.as.name'))