Erster Upload
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\User\Resources;
|
||||
|
||||
use App\Filament\User\Resources\BatchResource\Pages;
|
||||
use App\Models\Batch;
|
||||
use App\Models\Recipe;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class BatchResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Batch::class;
|
||||
protected static ?string $navigationIcon = 'heroicon-o-qr-code';
|
||||
protected static ?string $navigationLabel = 'Chargen (LOT)';
|
||||
protected static ?string $modelLabel = 'Charge';
|
||||
protected static ?string $pluralModelLabel = 'Chargen';
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form->schema([
|
||||
Forms\Components\Section::make('Charge')->schema([
|
||||
Forms\Components\TextInput::make('lot_number')
|
||||
->label('LOT-Nummer')
|
||||
->required()
|
||||
->unique(ignoreRecord: true)
|
||||
->maxLength(255),
|
||||
|
||||
Forms\Components\Select::make('product_id')
|
||||
->label('Produkt')
|
||||
->relationship('product', 'title')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required()
|
||||
->live(),
|
||||
|
||||
Forms\Components\Select::make('recipe_id')
|
||||
->label('Rezeptur')
|
||||
->relationship('recipe', 'name')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required()
|
||||
->live(),
|
||||
|
||||
Forms\Components\DatePicker::make('produced_at')
|
||||
->label('Produktionsdatum'),
|
||||
|
||||
Forms\Components\DatePicker::make('expires_at')
|
||||
->label('Mindesthaltbarkeitsdatum'),
|
||||
])->columns(2),
|
||||
|
||||
Forms\Components\Section::make('Herkunft der Gewürze')->schema([
|
||||
Forms\Components\Repeater::make('origins')
|
||||
->label('')
|
||||
->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')
|
||||
->reorderable(false),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('lot_number')
|
||||
->label('LOT-Nummer')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('product.title')
|
||||
->label('Produkt')
|
||||
->searchable(),
|
||||
|
||||
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')
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('product')
|
||||
->relationship('product', 'title')
|
||||
->label('Produkt'),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListBatches::route('/'),
|
||||
'create' => Pages\CreateBatch::route('/create'),
|
||||
'edit' => Pages\EditBatch::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user