Restructure batch origins: nested entries per ingredient with Supplier/Farmer selects
Deploy / deploy (push) Successful in 14s
Deploy / deploy (push) Successful in 14s
Each BatchOrigin (spice) now has multiple BatchOriginEntry rows, replacing the flat single-supplier/farmer fields. Lieferant and Landwirt are Select fields backed by dedicated tables with inline create support. Migration preserves existing data. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
400237aa5b
commit
4a98beeb45
6 files changed
+221
-89
No files matched your search
@@ -4,6 +4,7 @@ namespace App\Filament\User\Resources;
|
||||
|
||||
use App\Filament\User\Resources\BatchResource\Pages;
|
||||
use App\Models\Batch;
|
||||
use App\Models\Farmer;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductSize;
|
||||
use App\Models\Recipe;
|
||||
@@ -56,11 +57,8 @@ class BatchResource extends Resource
|
||||
$recipe = Recipe::with('spices')->find($product->recipes_id);
|
||||
if ($recipe) {
|
||||
$set('origins', $recipe->spices->map(fn ($s) => [
|
||||
'spice_id' => $s->id,
|
||||
'supplier_id' => null,
|
||||
'origin_country' => null,
|
||||
'farmer' => null,
|
||||
'notes' => null,
|
||||
'spice_id' => $s->id,
|
||||
'entries' => [['supplier_id' => null, 'origin_country' => null, 'farmer_id' => null, 'notes' => null]],
|
||||
])->toArray());
|
||||
}
|
||||
}
|
||||
@@ -93,11 +91,8 @@ class BatchResource extends Resource
|
||||
$recipe = Recipe::with('spices')->find($state);
|
||||
if ($recipe) {
|
||||
$set('origins', $recipe->spices->map(fn ($s) => [
|
||||
'spice_id' => $s->id,
|
||||
'supplier_id' => null,
|
||||
'origin_country' => null,
|
||||
'farmer' => null,
|
||||
'notes' => null,
|
||||
'spice_id' => $s->id,
|
||||
'entries' => [['supplier_id' => null, 'origin_country' => null, 'farmer_id' => null, 'notes' => null]],
|
||||
])->toArray());
|
||||
}
|
||||
}),
|
||||
@@ -133,34 +128,52 @@ class BatchResource extends Resource
|
||||
->label('')
|
||||
->relationship()
|
||||
->schema([
|
||||
Forms\Components\Select::make('spice_id')
|
||||
Forms\Components\Hidden::make('spice_id'),
|
||||
Forms\Components\Placeholder::make('spice_name')
|
||||
->label('Rohstoff')
|
||||
->options(Spice::orderBy('name')->pluck('name', 'id'))
|
||||
->searchable()
|
||||
->required(),
|
||||
->content(fn (Get $get): string =>
|
||||
Spice::find($get('spice_id'))?->name ?? '—'
|
||||
)
|
||||
->columnSpanFull(),
|
||||
|
||||
Forms\Components\Select::make('supplier_id')
|
||||
->label('Lieferant')
|
||||
->relationship('supplier', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->nullable(),
|
||||
Forms\Components\Repeater::make('entries')
|
||||
->label('Herkunftsangaben')
|
||||
->relationship()
|
||||
->schema([
|
||||
Forms\Components\Select::make('supplier_id')
|
||||
->label('Lieferant')
|
||||
->options(fn () => \App\Models\Supplier::orderBy('name')->pluck('name', 'id'))
|
||||
->searchable()
|
||||
->createOptionForm([
|
||||
Forms\Components\TextInput::make('name')->label('Name')->required(),
|
||||
])
|
||||
->createOptionUsing(fn ($data) => \App\Models\Supplier::create($data)->id)
|
||||
->nullable(),
|
||||
|
||||
Forms\Components\TextInput::make('origin_country')
|
||||
->label('Herkunftsland')
|
||||
->maxLength(100),
|
||||
Forms\Components\TextInput::make('origin_country')
|
||||
->label('Herkunftsland')
|
||||
->maxLength(100),
|
||||
|
||||
Forms\Components\TextInput::make('farmer')
|
||||
->label('Landwirt / Betrieb')
|
||||
->maxLength(255),
|
||||
Forms\Components\Select::make('farmer_id')
|
||||
->label('Landwirt')
|
||||
->options(fn () => Farmer::orderBy('name')->pluck('name', 'id'))
|
||||
->searchable()
|
||||
->createOptionForm([
|
||||
Forms\Components\TextInput::make('name')->label('Name')->required(),
|
||||
])
|
||||
->createOptionUsing(fn ($data) => Farmer::create($data)->id)
|
||||
->nullable(),
|
||||
|
||||
Forms\Components\Textarea::make('notes')
|
||||
->label('Notizen')
|
||||
->rows(2)
|
||||
Forms\Components\Textarea::make('notes')
|
||||
->label('Notizen')
|
||||
->rows(2)
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(3)
|
||||
->addActionLabel('Eintrag hinzufügen')
|
||||
->reorderable(false)
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(2)
|
||||
->addActionLabel('Eintrag hinzufügen')
|
||||
->reorderable(false),
|
||||
]),
|
||||
]);
|
||||
|
||||
Reference in new issue
Block a user