Files
SpiceManagementSystem/app/Filament/User/Resources/SpiceResource.php
T
2026-09-13 01:26:17 +02:00

103 lines
3.3 KiB
PHP

<?php
namespace App\Filament\User\Resources;
use App\Filament\User\Resources\SpiceResource\Pages;
use App\Filament\User\Resources\SpiceResource\RelationManagers;
use App\Models\Spice;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class SpiceResource extends Resource
{
protected static ?string $model = Spice::class;
protected static ?string $navgationLabel = 'Rohstoffe';
protected static ?string $modelLabel = 'Rohstoff';
protected static ?string $slug = 'rohstoffe';
protected static ?string $navigationGroup = 'Lager';
protected static bool $shouldRegisterNavigation = false;
protected static ?string $navigationIcon = 'heroicon-o-cube';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\Select::make('unit')
->label('Mengeneinheit')
->native(false)
->searchable()
->live()
->options([
'grams' => '(Kilo-)Gramm',
'pieces' => 'Stück',
'liter' => 'Liter',
])
->required(),
Forms\Components\TextInput::make('piece_weight')
->label('Ø Stückgewicht (g)')
->numeric()
->suffix('g')
->helperText('Wird automatisch aus Lieferungen errechnet, kann aber auch manuell gesetzt werden.')
->visible(fn (Get $get) => $get('unit') === 'pieces'),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable(),
Tables\Columns\TextColumn::make('unit')
->label('Einheit')
->formatStateUsing(fn ($state) => match($state) {
'grams' => '(Kilo-)Gramm',
'pieces' => 'Stück',
'liter' => 'Liter',
default => ucfirst($state),
}),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
RelationManagers\StockMovementsRelationManager::class,
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListSpices::route('/'),
'create' => Pages\CreateSpice::route('/create'),
'edit' => Pages\EditSpice::route('/{record}/edit'),
];
}
public static function getPluralLabel(): string
{
return 'Rohstoffe'; // Setze hier deinen eigenen Pluralbegriff ein
}
}