98 lines
3.2 KiB
PHP
98 lines
3.2 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\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 ?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()
|
|
->options([
|
|
'grams' => '(Kilo-)Gramm',
|
|
'pieces' => 'Stück',
|
|
'liter' => 'Liter',
|
|
])
|
|
->required(),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('name')
|
|
->searchable(),
|
|
Tables\Columns\TextColumn::make('quantity')->label('Menge lagernd')
|
|
->formatStateUsing(function (Spice $record) {
|
|
if ($record->unit == 'grams') {
|
|
return ($record->quantity >= 1000) ? round($record->quantity / 1000, 2) . 'kg' : $record->quantity . 'g';
|
|
}elseif($record->unit == 'pieces'){
|
|
return $record->quantity . ' Stück';
|
|
}elseif($record->unit == 'liter'){
|
|
return $record->quantity . ' Liter';
|
|
}else{
|
|
return $record->quantity . ' ' . ucfirst($record->unit);
|
|
}
|
|
}),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|