Embed recipe editing directly on product page
Deploy / deploy (push) Successful in 14s

Replaces the recipe dropdown with an inline Section containing a name
field and a spice-repeater with percentage inputs. On save, the recipe
is created (version 1) or updated in place; spice pivot rows are synced
via sync(). SumEquals100 rule enforces that percentages add up to 100.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Malek TellissiandClaude Sonnet 4.6 committed 2026-09-12 05:43:37 +02:00
1 parent af55857883
commit 4775cffaae
3 files changed
+100 -48

No files matched your search

@@ -3,6 +3,7 @@
namespace App\Filament\User\Resources\ProductResource\Pages;
use App\Filament\User\Resources\ProductResource;
use App\Models\Recipe;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
@@ -19,6 +20,7 @@ class EditProduct extends EditRecord
protected function afterSave(): void {
$this->syncSizes();
$this->syncRecipe();
}
protected function syncSizes(): void {
@@ -39,4 +41,33 @@ class EditProduct extends EditRecord
$product->sizes()->sync($sizes);
}
protected function syncRecipe(): void
{
$product = $this->record;
$name = $this->data['recipe_name'] ?? null;
$spices = $this->data['recipe_spices'] ?? [];
if (! $name) {
return;
}
$pivotData = collect($spices)->mapWithKeys(fn ($s) => [
$s['spice_id'] => ['amount_in_percent' => $s['amount_in_percent']],
])->toArray();
if ($product->recipe) {
$product->recipe->update(['name' => $name]);
$product->recipe->spices()->sync($pivotData);
} else {
$nextVersion = Recipe::where('product_id', $product->id)->max('version') + 1;
$recipe = Recipe::create([
'name' => $name,
'product_id' => $product->id,
'version' => $nextVersion,
]);
$recipe->spices()->sync($pivotData);
$product->update(['recipes_id' => $recipe->id]);
}
}
}