'$refresh', ]; public function removeTableFilter(string $filterName, ?string $field = null, bool $shouldTriggerUpdatedFiltersHook = true): void { $searchValues = preg_split('/\s+/', $this->search_left, -1, PREG_SPLIT_NO_EMPTY); if (($key = array_search($field, $searchValues)) !== false) { unset($searchValues[$key]); } if ($searchValues) { $this->search_left = implode(' ', $searchValues); } else { $this->search_left = ''; } $this->dispatch('reload_data_left'); } public function table(Table $table): Table { return $table ->query(LoadEvents::load($this->search_left)) ->columns([ MapperLeftColumn::make('left')->label(''), ]) ->searchable(['home.name', 'away.name']) ->defaultPaginationPageOption(5) ->filters([ Filter::make('events') ->schema([ Select::make(name: 'sport_id') ->default(auth()->user()->sport_id) ->prefixIcon(auth()->user()->sport->icon) ->selectablePlaceholder(false) ->hiddenLabel() ->columnSpan(2) ->preload() ->options(function () { return Sport::query()->where('is_active', 1)->pluck('name', 'id'); }) ->live() ->reactive() ->afterStateUpdated(function (callable $set, $livewire) { $livewire->dispatch('reload_data_left'); $livewire->dispatch('reload_data_right'); $set('country_id', null); $set('competition_group_id', null); }), // Select::make('country_id') // ->placeholder('Country') // ->hiddenLabel() // ->multiple() // ->columnSpan(2) // ->searchable() // ->preload() // ->options(function (Get $get) { // $res = Event::query()->where('sport_id', $get('sport_id'))->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('country_id')->pluck('country_id')->toArray(); // return Country::query()->whereIn('id', $res)->pluck('name', 'id'); // }) // ->live() // ->reactive() // ->afterStateUpdated(function (callable $set) { // $set('competition_group_id', null); // }), Select::make('competition_group_id') ->placeholder('League') ->hiddenLabel() ->label('') ->columnSpan(2) ->multiple() ->searchable() ->options(function (Get $get) { // if ($get('country_id')) { // $res = Event::query()->where('sport_id', $get('sport_id'))->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->whereIn('country_id', $get('country_id'))->groupBy('competition_group_id')->pluck('competition_group_id')->toArray(); // } else { // } $res = Event::query()->where('sport_id', $get('sport_id'))->where('betradar_id', 0)->where('starttime', '>', Carbon::now())->groupBy('competition_group_id')->pluck('competition_group_id')->toArray(); $comps = CompetitionGroup::with('country')->whereIn('id', $res)->get(); $arr = []; foreach ($comps as $val) { if (isset($val->country->name)) { $arr[$val->id] = $val->country->name.' - '.$val->name; } else { $arr[$val->id] = $val->name; } } asort($arr); return $arr; }) ->live(), ]) ->query(function (Builder $query, array $data): Builder { return $query ->when( $data['sport_id'], fn (Builder $query, $sport_id) => $query->where('sport_id', $sport_id) // )->when( // $data['country_id'], // fn (Builder $query, $country_id) => $query->where('country_id', $country_id) )->when( $data['competition_group_id'], fn (Builder $query, $competition_group_id) => $query->whereIn('competition_group_id', $competition_group_id) ); })->indicateUsing(function (): array { $indicators = []; if ($this->search_left) { $searchValues = preg_split('/\s+/', $this->search_left, -1, PREG_SPLIT_NO_EMPTY); foreach ($searchValues as $value) { $indicators[] = Indicator::make($value)->removeField($value); } } return $indicators; }) ->columns(4)->columnSpan(4), ], layout: FiltersLayout::AboveContent) ->filtersFormColumns(3) ->persistFiltersInSession() ->deferFilters(false) ->toolbarActions([ Action::make('reload_data_left') ->hiddenLabel() ->icon('phosphor-x') ->color('danger') ->size(Size::Small) ->action(function (Component $livewire) { $this->search_left = ''; $this->tableSearch = ''; // Clears the main search bar $livewire->fill(['tableSearch' => '']); $livewire->resetTableFiltersForm(); // Clears all filters $this->dispatch('reload_data_left'); }), ]); } public function toggle() { $this->elements_swopped = ! $this->elements_swopped; } #[On('search_left')] public function searchLeft($str) { $this->search_left = $str; $this->dispatch('reload_data_left'); } public function leftAction(): Action { return Action::make('left') ->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); $this->search_right = ''; $this->search_left = ''; $this->dispatch('reload_data_left'); $this->dispatch('reload_data_right'); }) ->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'); } }