'$refresh', ]; public function table(Table $table): Table { return $table ->query(LoadProvider::load()) ->columns([ MapperRightColumn::make('right')->label(''), ])->searchable(['home', 'away']) ->defaultPaginationPageOption(5) ->filters([ Filter::make('events') ->schema([ Select::make('country_id') ->visible(fn () => in_array(Auth()->user()->provider_id, [3, 4])) ->placeholder('Country') ->hiddenLabel() ->label('') ->searchable() ->preload() ->multiple() ->columnSpan(2) ->live() ->options(function () { return Mapper::query()->where('sport_id', Auth::user()->sport_id)->where('provider_id', Auth::user()->provider_id)->where('starttime', '>', Carbon::now())->groupBy('country_id')->pluck('country', 'country_id')->toArray(); }) ->reactive() ->afterStateUpdated(function (callable $set) { $set('group_id', null); }) ->placeholder('Country'), Select::make('group_cc') ->visible(fn () => Auth()->user()->provider_id == 2) ->placeholder('Country') ->hiddenLabel() ->label('') ->searchable() ->preload() ->multiple() ->columnSpan(2) ->live() ->options(function () { $res = Mapper::query()->where('sport_id', Auth::user()->sport_id)->where('provider_id', Auth::user()->provider_id)->where('starttime', '>', Carbon::now())->groupBy('group_cc')->pluck('group_cc')->toArray(); return Country::query()->whereIn('iso2', $res)->pluck('name', 'iso2'); }) ->reactive() ->afterStateUpdated(function (callable $set) { $set('group_id', null); }) ->placeholder('Country'), Select::make('group_id') ->placeholder('League') ->label('Leagues') ->hiddenLabel() ->label('') ->columnSpan(2) ->searchable() ->preload() ->multiple() ->options(function (Get $get) { if ($get('country_id')) { return Mapper::query()->where('sport_id', Auth::user()->sport_id)->where('provider_id', Auth::user()->provider_id)->where('starttime', '>', Carbon::now())->whereIn('country_id', $get('country_id'))->groupBy('group_id')->pluck('group', 'group_id')->toArray(); } elseif ($get('group_cc')) { return Mapper::query()->where('sport_id', Auth::user()->sport_id)->where('provider_id', Auth::user()->provider_id)->where('starttime', '>', Carbon::now())->whereIn('group_cc', $get('group_cc'))->groupBy('group_id')->pluck('group', 'group_id')->toArray(); } else { return Mapper::query()->where('sport_id', Auth::user()->sport_id)->where('provider_id', Auth::user()->provider_id)->where('starttime', '>', Carbon::now())->groupBy('group_id')->pluck('group', 'group_id')->toArray(); } }) ->live(), ]) ->query(function (Builder $query, array $data): Builder { return $query ->when( $data['country_id'], fn (Builder $query, $country_id) => $query->whereIn('country_id', $country_id) )->when( $data['group_cc'], fn (Builder $query, $group_cc) => $query->whereIn('group_cc', $group_cc) )->when( $data['group_id'], fn (Builder $query, $group_id) => $query->whereIn('group_id', $group_id) ); }) ->columns(4)->columnSpan(4), ], layout: FiltersLayout::AboveContent) // ->hiddenFilterIndicators() ->persistFiltersInSession() ->filtersFormColumns(3) ->deferFilters(false) ->toolbarActions([ Action::make('reload_data') ->hiddenLabel() ->color('gray') ->icon('heroicon-o-arrow-path') ->action(function (Component $livewire) { $livewire->resetTableFiltersForm(); // Clears all filters $this->tableSearch = ''; // Clears the main search bar }), ]); } public function toggle() { $this->elements_swopped = ! $this->elements_swopped; } public function rightAction(): Action { return Action::make('right') ->modalHeading('Event Mapper') ->modalContent(function (array $arguments) { $event = Event::where('id', $arguments['id'])->first(); $mapper = Mapper::where('event_id', $arguments['event_id'])->first(); return view('livewire.confirm-mapping', ['event' => $event, 'mapper' => $mapper]); })->action(function ($arguments) { StoreMapped::store($arguments, $this->elements_swopped); }) ->closeModalByEscaping(false) ->modalCloseButton(false) ->closeModalByClickingAway(false) ->modalAlignment(Alignment::Center) ->modalFooterActionsAlignment(Alignment::Center) ->modalWidth('2xl') ->modalSubmitActionLabel('Confirm') ->modalSubmitAction(); } public function render() { return view('livewire.mapper-left'); } }