From 400237aa5b7221bf952ed3471f3ef7aca206ffc3 Mon Sep 17 00:00:00 2001 From: Malek Tellissi Date: Sat, 12 Sep 2026 19:46:17 +0200 Subject: [PATCH] Allow multiple supplier/farmer entries per ingredient in batch origins MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each batch origin row now shows a searchable Rohstoff Select so the same ingredient can appear in multiple rows with different suppliers or farmers. Pre-fill from recipe still works (one row per ingredient); user clicks 'Eintrag hinzufügen' to add a second entry for the same ingredient. Co-Authored-By: Claude Sonnet 4.6 --- app/Filament/User/Resources/BatchResource.php | 18 +++++------------- .../BatchesRelationManager.php | 11 +++++------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/Filament/User/Resources/BatchResource.php b/app/Filament/User/Resources/BatchResource.php index 5358d29..302ca64 100644 --- a/app/Filament/User/Resources/BatchResource.php +++ b/app/Filament/User/Resources/BatchResource.php @@ -132,20 +132,12 @@ class BatchResource extends Resource Forms\Components\Repeater::make('origins') ->label('') ->relationship() - ->afterStateHydrated(function ($component, $record) { - // Pre-fill on create only when no origins exist - if ($record?->id) { - return; - } - // State is set reactively via recipe_id afterStateUpdated - }) ->schema([ - Forms\Components\Hidden::make('spice_id'), - Forms\Components\Placeholder::make('spice_name') + Forms\Components\Select::make('spice_id') ->label('Rohstoff') - ->content(fn (Get $get): string => - Spice::find($get('spice_id'))?->name ?? '—' - ), + ->options(Spice::orderBy('name')->pluck('name', 'id')) + ->searchable() + ->required(), Forms\Components\Select::make('supplier_id') ->label('Lieferant') @@ -168,7 +160,7 @@ class BatchResource extends Resource ->columnSpanFull(), ]) ->columns(2) - ->addActionLabel('Rohstoff hinzufügen') + ->addActionLabel('Eintrag hinzufügen') ->reorderable(false), ]), ]); diff --git a/app/Filament/User/Resources/ProductResource/RelationManagers/BatchesRelationManager.php b/app/Filament/User/Resources/ProductResource/RelationManagers/BatchesRelationManager.php index 1cf5066..7dbe46d 100644 --- a/app/Filament/User/Resources/ProductResource/RelationManagers/BatchesRelationManager.php +++ b/app/Filament/User/Resources/ProductResource/RelationManagers/BatchesRelationManager.php @@ -117,12 +117,11 @@ class BatchesRelationManager extends RelationManager ])->toArray()); }) ->schema([ - Forms\Components\Hidden::make('spice_id'), - Forms\Components\Placeholder::make('spice_name') + Forms\Components\Select::make('spice_id') ->label('Rohstoff') - ->content(fn (Get $get): string => - Spice::find($get('spice_id'))?->name ?? '—' - ), + ->options(Spice::orderBy('name')->pluck('name', 'id')) + ->searchable() + ->required(), Forms\Components\Select::make('supplier_id') ->label('Lieferant') @@ -145,7 +144,7 @@ class BatchesRelationManager extends RelationManager ->columnSpanFull(), ]) ->columns(2) - ->addActionLabel('Rohstoff hinzufügen') + ->addActionLabel('Eintrag hinzufügen') ->columnSpanFull(), ]); }