90 lines
2.7 KiB
PHP
90 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Countries;
|
|
|
|
use App\Filament\Clusters\Maintenance\MaintenanceCluster;
|
|
use App\Filament\Resources\Countries\Pages\ManageCountries;
|
|
use App\Models\Country;
|
|
use BackedEnum;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Enums\IconSize;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use UnitEnum;
|
|
|
|
class CountryResource extends Resource
|
|
{
|
|
protected static ?string $model = Country::class;
|
|
|
|
protected static ?int $navigationSort = 22;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = 'lucide-flag';
|
|
|
|
protected static ?string $recordTitleAttribute = 'name';
|
|
|
|
protected static string|UnitEnum|null $navigationGroup = 'Administration';
|
|
|
|
protected static ?string $cluster = MaintenanceCluster::class;
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->components([
|
|
TextInput::make('name')->required()->maxLength(255)->copyable(),
|
|
TextInput::make('icon')->maxLength(255),
|
|
TextInput::make('iso2')->maxLength(2),
|
|
TextInput::make('iso3')->maxLength(2),
|
|
TextInput::make('cc')->maxLength(2),
|
|
TextInput::make('numeric')->maxLength(2),
|
|
TextInput::make('txid')->maxLength(4),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->recordTitleAttribute('name')
|
|
->columns([
|
|
IconColumn::make('icon')
|
|
->sortable()
|
|
->icon(function ($state): string {
|
|
return $state;
|
|
})->label('Flags')->size(IconSize::TwoExtraLarge),
|
|
TextColumn::make('name')
|
|
->searchable()
|
|
->copyable()
|
|
->copyMessage('Name copied')
|
|
->copyMessageDuration(1500),
|
|
// TextColumn::make('iso2'),
|
|
TextColumn::make('iso3'),
|
|
TextColumn::make('cc'),
|
|
TextColumn::make('numeric'),
|
|
TextColumn::make('txid'),
|
|
|
|
])
|
|
->defaultSort('name', direction: 'asc')
|
|
->filters([
|
|
//
|
|
])
|
|
->recordActions([
|
|
EditAction::make(),
|
|
]);
|
|
}
|
|
|
|
public static function getNavigationBadge(): ?string
|
|
{
|
|
return parent::getEloquentQuery()->count();
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ManageCountries::route('/'),
|
|
];
|
|
}
|
|
}
|