Files
fotospiel-app/app/Filament/Resources/PackageResource.php

153 lines
4.9 KiB
PHP

<?php
namespace App\Filament\Resources;
use App\Filament\Resources\PackageResource\Pages;
use App\Models\Package;
use Filament\Forms;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Components\Repeater;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\IconColumn;
use Filament\Actions\EditAction;
use Filament\Actions\DeleteAction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use UnitEnum;
use BackedEnum;
class PackageResource extends Resource
{
protected static ?string $model = Package::class;
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-cube';
protected static string|UnitEnum|null $navigationGroup = null;
protected static ?int $navigationSort = 5;
public static function form(Schema $schema): Schema
{
return $schema->schema([
TextInput::make('name')
->label('Name')
->required()
->maxLength(255),
Select::make('type')
->label('Type')
->options([
'endcustomer' => 'Endcustomer',
'reseller' => 'Reseller',
])
->required(),
TextInput::make('price')
->label('Price')
->prefix('€')
->numeric()
->step(0.01)
->required()
->default(0),
TextInput::make('max_photos')
->label('Max Photos')
->numeric()
->nullable(),
TextInput::make('max_guests')
->label('Max Guests')
->numeric()
->nullable(),
TextInput::make('gallery_days')
->label('Gallery Days')
->numeric()
->nullable(),
TextInput::make('max_tasks')
->label('Max Tasks')
->numeric()
->nullable(),
Toggle::make('watermark_allowed')
->label('Watermark Allowed')
->default(true),
Toggle::make('branding_allowed')
->label('Branding Allowed')
->default(false),
TextInput::make('max_events_per_year')
->label('Max Events per Year')
->numeric()
->nullable(),
Repeater::make('features')
->label('Features')
->schema([
TextInput::make('key')
->label('Feature Key'),
TextInput::make('value')
->label('Feature Value'),
])
->columns(2)
->defaultItems(0),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name')
->label('Name')
->searchable()
->sortable(),
TextColumn::make('type')
->label('Type')
->badge()
->color(fn (string $state): string => match ($state) {
'endcustomer' => 'info',
'reseller' => 'warning',
default => 'gray',
}),
TextColumn::make('price')
->label('Price')
->money('EUR')
->sortable(),
IconColumn::make('max_photos')
->label('Max Photos')
->icon('heroicon-o-photo')
->color('primary'),
TextColumn::make('features')
->label('Features')
->limit(50),
])
->filters([
//
])
->actions([
EditAction::make(),
DeleteAction::make(),
])
->bulkActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListPackages::route('/'),
'create' => Pages\CreatePackage::route('/create'),
'edit' => Pages\EditPackage::route('/{record}/edit'),
];
}
}