diff --git a/app/Filament/User/Resources/ProductResource.php b/app/Filament/User/Resources/ProductResource.php index c79a029..1a54871 100644 --- a/app/Filament/User/Resources/ProductResource.php +++ b/app/Filament/User/Resources/ProductResource.php @@ -54,12 +54,6 @@ class ProductResource extends Resource { ->columnSpanFull(), Forms\Components\Section::make('Rezept') ->schema([ - TextInput::make('recipe_name') - ->label('Name') - ->required() - ->dehydrated(false) - ->afterStateHydrated(fn ($component, $record) => - $component->state($record?->recipe?->name ?? '')), Placeholder::make('recipe_version') ->label('Version') ->content(fn ($record) => $record?->recipe diff --git a/app/Filament/User/Resources/ProductResource/Pages/CreateProduct.php b/app/Filament/User/Resources/ProductResource/Pages/CreateProduct.php index 48accaa..c43f1dc 100644 --- a/app/Filament/User/Resources/ProductResource/Pages/CreateProduct.php +++ b/app/Filament/User/Resources/ProductResource/Pages/CreateProduct.php @@ -27,12 +27,11 @@ class CreateProduct extends CreateRecord ]); } - $recipeName = $data['recipe_name'] ?? null; - $spices = $data['recipe_spices'] ?? []; + $spices = $data['recipe_spices'] ?? []; - if ($recipeName) { + if (! empty($spices)) { $recipe = Recipe::create([ - 'name' => $recipeName, + 'name' => $data['title'], 'product_id' => $record->id, 'version' => 1, ]); diff --git a/app/Filament/User/Resources/ProductResource/Pages/EditProduct.php b/app/Filament/User/Resources/ProductResource/Pages/EditProduct.php index 9999f53..32d991b 100644 --- a/app/Filament/User/Resources/ProductResource/Pages/EditProduct.php +++ b/app/Filament/User/Resources/ProductResource/Pages/EditProduct.php @@ -52,10 +52,9 @@ class EditProduct extends EditRecord protected function syncRecipe(): void { $product = $this->record; - $name = $this->data['recipe_name'] ?? null; $spices = $this->data['recipe_spices'] ?? []; - if (! $name) { + if (empty($spices)) { return; } @@ -72,10 +71,7 @@ class EditProduct extends EditRecord $s->id => (float) $s->pivot->amount_in_percent, ])->toArray(); - $nameChanged = $current->name !== $name; - $spicesChanged = $existingPivot != $newPivot; - - if (! $nameChanged && ! $spicesChanged) { + if ($existingPivot == $newPivot) { return; } } @@ -83,7 +79,7 @@ class EditProduct extends EditRecord $nextVersion = Recipe::where('product_id', $product->id)->max('version') + 1; $recipe = Recipe::create([ - 'name' => $name, + 'name' => $product->title, 'product_id' => $product->id, 'version' => $nextVersion, ]); diff --git a/app/Filament/User/Resources/ProductResource/Pages/RecipeHistory.php b/app/Filament/User/Resources/ProductResource/Pages/RecipeHistory.php index 8df1a05..b41604d 100644 --- a/app/Filament/User/Resources/ProductResource/Pages/RecipeHistory.php +++ b/app/Filament/User/Resources/ProductResource/Pages/RecipeHistory.php @@ -60,8 +60,6 @@ class RecipeHistory extends Page implements HasTable ->formatStateUsing(fn ($state) => 'v' . $state) ->badge() ->color(fn (Recipe $recipe) => $recipe->id === $currentRecipeId ? 'success' : 'gray'), - TextColumn::make('name') - ->label('Name'), TextColumn::make('spices_summary') ->label('Zutaten') ->state(fn (Recipe $recipe) =>