From 7dfd01c11a6a5c5cf8f113ae7d805cc6ce5a5cc9 Mon Sep 17 00:00:00 2001 From: Malek Tellissi Date: Sat, 12 Sep 2026 21:17:38 +0200 Subject: [PATCH] =?UTF-8?q?Remove=20standalone=20RecipeResource=20?= =?UTF-8?q?=E2=80=94=20recipes=20managed=20via=20product=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- .../User/Resources/RecipeResource.php | 125 ------------------ .../RecipeResource/Pages/CreateRecipe.php | 28 ---- .../RecipeResource/Pages/EditRecipe.php | 31 ----- .../RecipeResource/Pages/ListRecipes.php | 19 --- 4 files changed, 203 deletions(-) delete mode 100644 app/Filament/User/Resources/RecipeResource.php delete mode 100644 app/Filament/User/Resources/RecipeResource/Pages/CreateRecipe.php delete mode 100644 app/Filament/User/Resources/RecipeResource/Pages/EditRecipe.php delete mode 100644 app/Filament/User/Resources/RecipeResource/Pages/ListRecipes.php diff --git a/app/Filament/User/Resources/RecipeResource.php b/app/Filament/User/Resources/RecipeResource.php deleted file mode 100644 index e221dbf..0000000 --- a/app/Filament/User/Resources/RecipeResource.php +++ /dev/null @@ -1,125 +0,0 @@ -schema([ - TextInput::make('name') - ->required() - ->label('Name'), - Textarea::make('description') - ->label('Beschreibung'), - Repeater::make('spices') - ->schema([ - Select::make('spice_id') - ->label('Rohstoff') - ->options(Spice::all()->pluck('name', 'id')) - ->searchable() - ->required(), - - TextInput::make('amount_in_percent') - ->label('Anteil (in Prozent)') - ->numeric() - ->required() - ->rules(['min:1', 'max:100']), - ]) - ->label('Inhalt') - ->columns(2) - ->addActionLabel('Inhaltsstoff hinzufügen') - ->afterStateHydrated(function ($state, $set, $record) { - if ($record) { - // Load the spices relationship with pivot data - $record->load('spices'); - - // Map the spices and their pivot data to the format the repeater expects - $spicesData = $record->spices->map(function ($spice) { - return [ - 'spice_id' => $spice->id, - 'amount_in_percent' => $spice->pivot->amount_in_percent, - ]; - })->toArray(); - - // Set the state for the repeater field to the mapped spices data - $set('spices', $spicesData); - } - return $state; - }) - ->rules([new SumEquals100()]), - ]); - } -/* - */ - - public static function table(Table $table): Table - { - return $table - ->columns([ - TextColumn::make('name') - ->label('Name') - ->sortable() - ->searchable(), - TextColumn::make('description') - ->label('Beschreibung') - ->limit(50), - TextColumn::make('spices.name') - ->label('Inhalt') - ->formatStateUsing(function ($state, $record) { - $spices = $record->spices->take(3)->map(function ($spice) { - return $spice->name . ' (' . round($spice->pivot->amount_in_percent) . '%)'; - }); - - if ($record->spices->count() > 3) { - $spices->push('... weitere'); - } - - return $spices->implode(', '); - }) - ->limit(50), - ]); - } - - public static function getRecord($id) { - return Recipe::with('spices')->findOrFail($id); // Eager load spices relationship - } - - public static function getPages(): array - { - return [ - 'index' => Pages\ListRecipes::route('/'), - 'create' => Pages\CreateRecipe::route('/create'), - 'edit' => Pages\EditRecipe::route('/{record}/edit'), - ]; - } - public static function getPluralLabel(): string - { - return 'Rezepte'; - } -} diff --git a/app/Filament/User/Resources/RecipeResource/Pages/CreateRecipe.php b/app/Filament/User/Resources/RecipeResource/Pages/CreateRecipe.php deleted file mode 100644 index 96bc4ef..0000000 --- a/app/Filament/User/Resources/RecipeResource/Pages/CreateRecipe.php +++ /dev/null @@ -1,28 +0,0 @@ - $record->id, - 'spice_id' => $spice['spice_id'], - 'amount_in_percent' => $spice['amount_in_percent'], - ]); - } - return $record; - } - -} diff --git a/app/Filament/User/Resources/RecipeResource/Pages/EditRecipe.php b/app/Filament/User/Resources/RecipeResource/Pages/EditRecipe.php deleted file mode 100644 index d6c2d5a..0000000 --- a/app/Filament/User/Resources/RecipeResource/Pages/EditRecipe.php +++ /dev/null @@ -1,31 +0,0 @@ -syncSpices(); - } - - protected function syncSpices(): void - { - $recipe = $this->record; - - $spices = collect($this->data['spices'] ?? []) - ->mapWithKeys(function ($spice) { - return [ - $spice['spice_id'] => ['amount_in_percent' => $spice['amount_in_percent']], - ]; - }) - ->toArray(); - - $recipe->spices()->sync($spices); - } -} - diff --git a/app/Filament/User/Resources/RecipeResource/Pages/ListRecipes.php b/app/Filament/User/Resources/RecipeResource/Pages/ListRecipes.php deleted file mode 100644 index 6019af4..0000000 --- a/app/Filament/User/Resources/RecipeResource/Pages/ListRecipes.php +++ /dev/null @@ -1,19 +0,0 @@ -