fix(filament): added create option using (#714)

This commit is contained in:
Kyrch
2024-07-09 15:41:09 -03:00
committed by GitHub
parent 85878dc7c1
commit 115e5b32f6
2 changed files with 4 additions and 2 deletions
@@ -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) {
+1 -2
View File
@@ -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'))