striped() ->columns([ IconColumn::make('sport_id') ->label('') ->icon(fn (string $state): string => match ($state) { '1' => 'icon-soccerball', '2' => 'icon-icehockey', '3' => 'icon-basketball', '5' => 'icon-tennisball', }), TextColumn::make('league.name')->searchable(), TextColumn::make('starttime')->dateTime('M j, Y')->label('Date'), TextColumn::make('home.name')->color('primary')->searchable(), TextColumn::make('away.name')->color('success')->searchable(), ]) ->filters([ Filter::make('events') ->columns(5)->columnSpan(5) ->schema([ Select::make('sport_id') ->default(1) ->hiddenLabel() ->options(Sport::whereIn('id', [1, 2, 3, 5])->pluck('name', 'id')), Select::make(name: 'country_id') ->hidden(fn (Get $get) => $get('sport_id') == 5) ->placeholder('Country') ->prefixIcon('phosphor-flag') ->hiddenLabel() ->searchable() ->options(function (Get $get) { $res = Event::where('has_markets', 1) ->where('sport_id', $get('sport_id')) ->groupBy('country_id') ->pluck('country_id')->toArray(); return Country::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id'); }) ->live() ->reactive() ->afterStateUpdated(function (callable $set) { $set('competition_group_id', null); }), Select::make('competition_group_id') ->placeholder(fn (Get $get) => $get('sport_id') == 5 ? 'Tournament' : 'League') ->prefixIcon('phosphor-trophy') ->hiddenLabel() // ->multiple() ->searchable() ->options(function (Get $get) { $country_id = $get('country_id') ?? 0; $res = Event::with('country') ->with('competition_group') ->where('sport_id', $get('sport_id')) ->when($country_id, function ($query, $country_id) { $query->where('country_id', $country_id); })->groupBy('competition_group_id')->get(); $arr = []; foreach ($res as $val) { $arr[(int) $val->competition_group_id] = $val->country?->name.' '.$val->competition_group?->name; } asort($arr); return $arr; }) ->live(), DatePicker::make('starttime_from') ->prefix(fn () => new HtmlString('From')) ->displayFormat('d M Y') ->hiddenLabel() ->label(''), DatePicker::make('starttime_to') ->prefix(fn () => new HtmlString('To:')) ->displayFormat('d M Y') ->hiddenLabel() ->label(''), ]) ->query(function (Builder $query, array $data): Builder { return $query->when( $data['sport_id'], function (Builder $query, $sport_id) { $query->where('sport_id', (int) $sport_id); } )->when( $data['competition_group_id'], function (Builder $query, $competition_group_id) { // dd($competition_group_id); $query->where('league_id', (int) $competition_group_id); } )->when( $data['starttime_from'], function (Builder $query, $starttime_from) { if (isset($starttime_from)) { $from = Carbon::createFromDate($starttime_from); return $query->where('starttime', '>=', $starttime_from); } } )->when( $data['starttime_to'], function (Builder $query, $starttime_to) { if (isset($starttime_to)) { $to = Carbon::createFromDate($starttime_to); return $query->where('starttime', '<=', $starttime_to); } } ); })->indicateUsing(function (array $data): array { $indicators = []; if ($data['starttime_from'] ?? null) { $starttime_from = $data['starttime_from']; if ($starttime_from ?? null) { $text = Carbon::parse($starttime_from)->format('d. M. Y'); $indicators[] = Indicator::make('From: '.$text)->removeField('starttime_from')->color('info'); } } if ($data['starttime_to'] ?? null) { $starttime_to = $data['starttime_to']; if ($starttime_to ?? null) { $text = Carbon::parse($starttime_to)->format('d. M. Y'); $indicators[] = Indicator::make('To: '.$text)->removeField('starttime_to')->color('success'); } } if ($data['country_id'] ?? null) { $country_id = $data['country_id']; if ($country_id ?? null) { $text = Country::where('id', $country_id)->value('name'); $indicators[] = Indicator::make('Country: '.$text)->removeField('country_id'); } } // if ($data['competition_group_id'] ?? null) { // $competition_groups = CompetitionGroup::whereIn('id', $data['competition_group_id'])->pluck('name')->toArray(); // if (count($competition_groups) > 1) { // $indicators[] = Indicator::make(implode(', ', $competition_groups))->removeField('competition_group_id')->color('info'); // } else { // $indicators[] = Indicator::make($competition_groups[0])->removeField('competition_group_id')->color('info')->color('info'); // } // } return $indicators; }), ], layout: FiltersLayout::AboveContent) ->deferFilters(false) ->hiddenFilterIndicators(false) ->persistFiltersInSession() ->recordActions([ EditAction::make(), ]) ->toolbarActions([ BulkActionGroup::make([ DeleteBulkAction::make(), ]), ]); } }