117 lines
3.5 KiB
PHP
117 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Clusters\Cards\Cards;
|
|
|
|
use App\Filament\Clusters\Cards\Cards\Pages\ManageCards;
|
|
use App\Filament\Clusters\Cards\CardsCluster;
|
|
use App\Modules\AppHelpers\Repositories\DateHelper;
|
|
use App\Modules\Card\Models\Card;
|
|
use BackedEnum;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Forms\Components\Hidden;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
|
|
class CardResource extends Resource
|
|
{
|
|
protected static ?string $model = Card::class;
|
|
|
|
protected static ?string $cluster = CardsCluster::class;
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCreditCard;
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema
|
|
->columns(3)
|
|
->components([
|
|
Hidden::make('user_id')
|
|
->default(fn () => user()->id),
|
|
|
|
TextInput::make('number')
|
|
->label(__('Card number'))
|
|
->mask('9999 9999 9999 9999')
|
|
->columnSpan('1')
|
|
->required(),
|
|
|
|
Select::make('month')
|
|
->label(__('Card month'))
|
|
->options(DateHelper::staticNumberMonths())
|
|
->native(false)
|
|
->columnSpan('1')
|
|
->required(),
|
|
|
|
Select::make('year')
|
|
->label(__('Card year'))
|
|
->options(DateHelper::staticNumberYears())
|
|
->native(false)
|
|
->columnSpan('1')
|
|
->required(),
|
|
|
|
TextInput::make('name')
|
|
->label(__('Card name'))
|
|
->maxLength(255)
|
|
->columnSpanFull()
|
|
->required(),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('number')
|
|
->label(__('Card number'))
|
|
->searchable(),
|
|
|
|
TextColumn::make('name')
|
|
->label(__('Card name'))
|
|
->searchable(),
|
|
|
|
TextColumn::make('month')
|
|
->label(__('Card month'))
|
|
->searchable(),
|
|
|
|
TextColumn::make('year')
|
|
->label(__('Card year'))
|
|
->searchable(),
|
|
|
|
TextColumn::make('created_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
TextColumn::make('updated_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->filters([
|
|
//
|
|
])
|
|
->recordActions([
|
|
EditAction::make(),
|
|
DeleteAction::make(),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ManageCards::route('/'),
|
|
];
|
|
}
|
|
}
|