Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\SistemaResource\Pages;
|
||||
use App\Models\Sistema;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class SistemaResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Sistema::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $slug = 'sistemi';
|
||||
|
||||
protected static ?string $navigationGroup = 'Prodotti';
|
||||
|
||||
protected static ?string $navigationLabel = 'Sistemi';
|
||||
|
||||
protected static ?string $modelLabel = 'sistema';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'sistemi';
|
||||
|
||||
protected static ?int $navigationSort = 10;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form->schema([
|
||||
Forms\Components\Section::make()
|
||||
->columns(2)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('codice')
|
||||
->label('Codice')
|
||||
->helperText('Usato dal configuratore nel parametro ?sistema= (es. pvc).')
|
||||
->required()
|
||||
->maxLength(50)
|
||||
->alphaDash()
|
||||
->unique(ignoreRecord: true),
|
||||
Forms\Components\TextInput::make('nome')
|
||||
->label('Nome')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\TextInput::make('ordine')
|
||||
->label('Ordine')
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->default(0),
|
||||
Forms\Components\Toggle::make('attivo')
|
||||
->label('Attivo nel configuratore')
|
||||
->default(true)
|
||||
->inline(false),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('ordine')
|
||||
->reorderable('ordine')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('codice')->label('Codice')->searchable(),
|
||||
Tables\Columns\TextColumn::make('nome')->label('Nome')->searchable(),
|
||||
Tables\Columns\TextColumn::make('modelli_count')->label('Modelli')->counts('modelli'),
|
||||
Tables\Columns\IconColumn::make('attivo')->label('Attivo')->boolean(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\Action::make('modelli')
|
||||
->label('Modelli')
|
||||
->icon('heroicon-o-squares-2x2')
|
||||
->color('gray')
|
||||
->url(fn (Sistema $record) => ModelloResource::getUrl('index', [
|
||||
'tableFilters' => ['sistema' => ['value' => $record->getKey()]],
|
||||
])),
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make()
|
||||
->modalDescription('Verrà eliminato definitivamente il sistema insieme a tutti i suoi modelli.'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSistemi::route('/'),
|
||||
'create' => Pages\CreateSistema::route('/create'),
|
||||
'edit' => Pages\EditSistema::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user