striped() ->columns([ IconColumn::make('sport.icon') ->sortable() ->label('') ->grow(false) ->width(30) ->icon(fn($record) => $record->sport->icon) ->tooltip(fn($record) => $record->id) ->visibleFrom('lg'), TextColumn::make('id') ->sortable() ->tooltip('click to copy') ->alignCenter() ->copyable(), TextColumn::make('name') ->sortable() ->sortable() ->searchable() ->color('primary'), TextColumn::make('country.name') ->wrap() ->sortable() ->color('gray') ->icon(fn($record) => $record->country->icon), TextColumn::make('element_group.competition_group_id')->label('Group Id') ->sortable() ->alignCenter() ->tooltip('click to copy') ->copyable(), TextColumn::make('element_group.competition_group.name')->label('Group') ->sortable(), // TextColumn::make('element_group.group.name')->label('Group'), ImageColumn::make('betsapi_image_id') ->label('Logo') ->defaultImageUrl(fn($state) => url('https://assets.b365api.com/images/team/m/' . $state . '.png')), ])->filters([ SelectFilter::make('sport_id') ->label('Sport') ->options(Sport::where('is_active', 1)->pluck('name', 'id')), Filter::make('competition_group') ->columns(3)->columnSpan(3) ->schema([ Select::make('country_id') ->searchable() ->label('Country') ->options(Country::orderBy('name')->pluck('name', 'id')) ->live(), Select::make('competition_group_id') ->searchable() ->label('Competition Group') ->options(function (Get $get) { if ($get('country_id')) { return CompetitionGroup::where('country_id', $get('country_id'))->orderBy('name')->pluck('name', 'id'); } else { return CompetitionGroup::orderBy('name')->pluck('name', 'id'); } }), ]) ->query(function (Builder $query, array $data): Builder { return $query->when( $data['country_id'], fn(Builder $query, $country_id) => $query->where('country_id', $country_id) )->when( $data['competition_group_id'], function (Builder $query, $competition_group_id) { return $query->whereHas('element_group', function (Builder $query) use ($competition_group_id) { return $query->where('competition_group_id', $competition_group_id); }); } ); }), ], layout: FiltersLayout::AboveContent) ->deferFilters(false) ->recordActions([ ActionGroup::make([ EditAction::make(), DeleteAction::make() ->tooltip('All elements connected to this group, including active events, will be deleted') ->before(function ($record) { Event::where('home_id', $record->id)->delete(); Event::where('away_id', $record->id)->delete(); ElementProvider::where('element_id', $record->id)->delete(); ElementGroup::where('element_id', $record->id)->delete(); }) ->successNotification( Notification::make() ->success() ->title('Element deleted') ->body('The element with all relations in other tables has been deleted successfully.'), ), ])->iconButton() ->icon('phosphor-dots-three-vertical'), ]) ->headerActions([ ExportAction::make() ->modalHeading('Download Teams/Player') ->color('warning') ->label('Export') ->icon('phosphor-download') ->modalDescription('This will download the TxOdds Teams/Player with "sport_id" and "country_id" for the sport selected.') ->modalIcon('phosphor-microsoft-excel-logo') ->exporter(ElementExporter::class) ->columnMapping(false) ->formats([ ExportFormat::Xlsx, ExportFormat::Csv, ]), ]) ->toolbarActions([ BulkActionGroup::make([ DeleteBulkAction::make(), ]), ]); } }