86 lines
3.3 KiB
PHP
86 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Clusters\DynamicData\Resources\CompetitionGroups\Tables;
|
|
|
|
use App\Models\CompetitionGroupProvider;
|
|
use App\Models\Country;
|
|
use App\Models\ElementGroup;
|
|
use App\Models\Event;
|
|
use App\Models\Group;
|
|
use App\Models\Sport;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteAction;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\SelectColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Enums\FiltersLayout;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
|
|
class CompetitionGroupsTable
|
|
{
|
|
public static function configure(Table $table): Table
|
|
{
|
|
return $table
|
|
->striped()
|
|
->columns([
|
|
IconColumn::make('sport.icon')
|
|
->label('')
|
|
->grow(false)
|
|
->color('primary')
|
|
->width(30)
|
|
->icon(fn ($record) => $record->sport->icon)
|
|
->tooltip(fn ($record) => $record->id)
|
|
->visibleFrom('lg'),
|
|
TextColumn::make('country.name')
|
|
->wrap()
|
|
->color('gray')
|
|
->label('Event')
|
|
->icon(fn ($record) => $record->country->icon),
|
|
TextColumn::make('name')
|
|
->searchable(),
|
|
SelectColumn::make('level')
|
|
->width(30)
|
|
->options([
|
|
'TOP' => 'TOP',
|
|
'MEDIUM' => 'MEDIUM',
|
|
'LOW' => 'LOW',
|
|
]),
|
|
])->filters([
|
|
SelectFilter::make('sport_id')
|
|
->label('Sport')
|
|
->options(fn () => Sport::where('is_active', 1)->pluck('name', 'id')->toArray()),
|
|
SelectFilter::make('country_id')
|
|
->searchable()
|
|
->label('Countries')
|
|
->options(fn () => Country::orderBy('name')->pluck('name', 'id')->toArray()),
|
|
], layout: FiltersLayout::AboveContent)
|
|
->deferFilters(false)
|
|
->recordActions([
|
|
EditAction::make(),
|
|
DeleteAction::make()
|
|
->tooltip('All elements connected to this group, including active events, will be deleted')
|
|
->before(function ($record) {
|
|
Group::where('competition_group_id', $record->id)->delete();
|
|
Event::where('competition_group_id', $record->id)->delete();
|
|
ElementGroup::where('competition_group_id', $record->id)->delete();
|
|
CompetitionGroupProvider::where('competition_group_id', $record->id)->delete();
|
|
})
|
|
->successNotification(
|
|
Notification::make()
|
|
->success()
|
|
->title('Group deleted')
|
|
->body('The group and all relations has been deleted successfully.'),
|
|
),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
}
|