83 lines
3.1 KiB
PHP
83 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Events\Tables;
|
|
|
|
use App\Filament\Tables\Columns\MultilineColumn;
|
|
use App\Models\Event;
|
|
use Carbon\Carbon;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Support\Enums\FontWeight;
|
|
use Filament\Support\Enums\IconSize;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Enums\FiltersLayout;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
|
|
class EventsTable
|
|
{
|
|
public static function configure(Table $table): Table
|
|
{
|
|
return $table
|
|
->striped()
|
|
->columns([
|
|
IconColumn::make('sport.icon')
|
|
->label('')
|
|
->width('1rem')
|
|
->size(IconSize::ExtraLarge)
|
|
->icon(fn ($record) => $record->sport->icon)
|
|
->tooltip(fn ($record) => $record->id),
|
|
TextColumn::make('tx_id')->label('Id')->badge()->copyable()->searchable(),
|
|
TextColumn::make('starttime')
|
|
->label('Start')
|
|
->alignCenter()
|
|
->dateTime('d.m')
|
|
->weight(FontWeight::Bold)
|
|
->description(fn ($state): string => Carbon::createFromDate($state)->format('H:i')),
|
|
TextColumn::make('country.name')
|
|
->color('gray')
|
|
->label('Event')
|
|
->icon(fn ($record) => $record->country->icon)
|
|
->description(fn ($record) => $record->competition_group->name),
|
|
TextColumn::make('home.name')->alignRight()->searchable(),
|
|
TextColumn::make('away.name')->searchable(),
|
|
|
|
MultilineColumn::make('id')
|
|
->searchable()
|
|
->label(fn () => view('filament.tables.columns.multiline.label')),
|
|
|
|
])
|
|
->poll('10s')
|
|
->defaultSort('starttime', 'ASC')
|
|
->filters([
|
|
SelectFilter::make('competition_group_id')
|
|
->preload()
|
|
->label('League')
|
|
->multiple()
|
|
->searchable()
|
|
->options(function () {
|
|
|
|
$res = Event::with('country')->with('competition_group')->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->get();
|
|
$arr = [];
|
|
foreach ($res as $val) {
|
|
$arr[$val->competition_group_id] = $val->country->name.' - '.$val->competition_group->name;
|
|
}
|
|
|
|
asort($arr);
|
|
|
|
return $arr;
|
|
})
|
|
->columnSpan(2)
|
|
->selectablePlaceholder(false),
|
|
], layout: FiltersLayout::AboveContent)
|
|
->filtersFormColumns(6)
|
|
->deferFilters(false)
|
|
->persistFiltersInSession()
|
|
->recordActions([
|
|
// EditAction::make(),
|
|
// DeleteAction::make()->iconButton(),
|
|
]);
|
|
}
|
|
}
|