Add recipe inline create/edit and batches relation on product page
Deploy / deploy (push) Successful in 14s

- Recipe select now has a create/edit modal (name + description)
- Batches RelationManager shows all LOT charges for the product below
  the form, sorted newest first, with create/edit/delete actions

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:10:04 +02:00
1 parent e959faff8d
commit 6e28984278
2 files changed
+130 -1

No files matched your search

@@ -52,7 +52,21 @@ class ProductResource extends Resource {
->native(false) ->native(false)
->searchable() ->searchable()
->relationship('recipe', 'name') ->relationship('recipe', 'name')
->required(), ->required()
->createOptionForm([
Forms\Components\TextInput::make('name')
->label('Name')
->required(),
Forms\Components\Textarea::make('description')
->label('Beschreibung'),
])
->editOptionForm([
Forms\Components\TextInput::make('name')
->label('Name')
->required(),
Forms\Components\Textarea::make('description')
->label('Beschreibung'),
]),
Repeater::make('sizes') Repeater::make('sizes')
->schema([ ->schema([
Select::make('packing_id') Select::make('packing_id')
@@ -140,6 +154,12 @@ class ProductResource extends Resource {
]); ]);
} }
public static function getRelations(): array {
return [
RelationManagers\BatchesRelationManager::class,
];
}
public static function getPages(): array { public static function getPages(): array {
return [ return [
'index' => Pages\ListProducts::route('/'), 'index' => Pages\ListProducts::route('/'),
@@ -0,0 +1,109 @@
<?php
namespace App\Filament\User\Resources\ProductResource\RelationManagers;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
class BatchesRelationManager extends RelationManager
{
protected static string $relationship = 'batches';
protected static ?string $title = 'Chargen (LOT)';
protected static ?string $modelLabel = 'Charge';
protected static ?string $pluralModelLabel = 'Chargen';
public function form(Form $form): Form
{
return $form->schema([
Forms\Components\TextInput::make('lot_number')
->label('LOT-Nummer')
->required()
->unique(ignoreRecord: true)
->maxLength(255),
Forms\Components\Select::make('recipe_id')
->label('Rezeptur')
->relationship('recipe', 'name')
->searchable()
->preload()
->required(),
Forms\Components\DatePicker::make('produced_at')
->label('Produktionsdatum'),
Forms\Components\DatePicker::make('expires_at')
->label('Mindesthaltbarkeitsdatum'),
Forms\Components\Repeater::make('origins')
->label('Herkunft der Gewürze')
->relationship()
->schema([
Forms\Components\Select::make('spice_id')
->label('Gewürz')
->relationship('spice', 'name')
->searchable()
->preload()
->required(),
Forms\Components\Select::make('supplier_id')
->label('Lieferant')
->relationship('supplier', 'name')
->searchable()
->preload()
->nullable(),
Forms\Components\TextInput::make('origin_country')
->label('Herkunftsland')
->maxLength(100),
Forms\Components\TextInput::make('farmer')
->label('Landwirt / Betrieb')
->maxLength(255),
Forms\Components\Textarea::make('notes')
->label('Infos zum Gewürz')
->rows(2)
->columnSpanFull(),
])
->columns(2)
->addActionLabel('Gewürz hinzufügen')
->columnSpanFull(),
]);
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('lot_number')
->columns([
Tables\Columns\TextColumn::make('lot_number')
->label('LOT-Nummer')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('recipe.name')
->label('Rezeptur'),
Tables\Columns\TextColumn::make('produced_at')
->label('Produktion')
->date('d.m.Y')
->sortable(),
Tables\Columns\TextColumn::make('expires_at')
->label('MHD')
->date('d.m.Y')
->sortable(),
])
->defaultSort('produced_at', 'desc')
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->headerActions([
Tables\Actions\CreateAction::make(),
]);
}
}