'$refresh', ]; public function removeTableFilter(string $filterName, ?string $field = null, bool $shouldTriggerUpdatedFiltersHook = true): void { $searchValues = preg_split('/\s+/', $this->search_right, -1, PREG_SPLIT_NO_EMPTY); if (($key = array_search($field, $searchValues)) !== false) { unset($searchValues[$key]); } if ($searchValues) { $this->search_right = implode(' ', $searchValues); } else { $this->search_right = ''; } $this->dispatch('refreshMapperRight'); } public function table(Table $table): Table { return $table ->query(LoadProvider::load($this->search_right, auth()->user())) ->columns([ MapperRightColumn::make('right')->label(''), TextColumn::make('home') ->color('home') ->weight(FontWeight::Bold) ->alignRight(), IconColumn::make('id')->icon('phosphor-minus')->label('')->color('black'), TextColumn::make('away') ->color('away') ->weight(FontWeight::Bold), TextColumn::make('group') ->wrap() ->tooltip('Click to filter by this group') ->description(fn ($record): string => $record->country_betsapi?->name.' '.$record->country) ->action(function ($record) { if (! in_array($record->group_id, $this->tableFilters['events']['group_id'])) { $this->tableFilters['events']['group_id'][] = (string) $record->group_id; $this->dispatch('refreshMapperRight'); } }), IconColumn::make('group_cc')->icon(fn (string $state): string => 'flag-country-'.$state)->label(''), TextColumn::make('starttime') ->sortable() ->time('H:i') ->alignCenter() ->description(fn ($record): string => Carbon::parse($record->starttime)->format('d. M. y')), ])->searchable(['home', 'away']) ->recordActions([ Action::make('search_home') ->iconButton() ->icon('phosphor-magnifying-glass') ->color('home') ->action(function ($record) { $this->dispatch('search_left', $record->home); }), Action::make('search_away') ->icon('phosphor-magnifying-glass') ->iconButton() ->color('away') ->action(function ($record) { $this->dispatch('search_left', $record->away); }), ], position: RecordActionsPosition::BeforeColumns) ->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() ->live() ->options(function (Get $get) { 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() ->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('') ->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())->where('country_id', $get('country'))->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())->where('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(), DateRangePicker::make('starttime_period') ->columnSpan(2) ->displayFormat('d M Y') ->minDate(now()) ->hiddenLabel() ->label('') ->live(), ]) ->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['group_cc'], fn (Builder $query, $group_cc) => $query->where('group_cc', $group_cc) )->when( $data['group_id'], function (Builder $query, $group_id) { $this->setPage(1); return $query->whereIn('group_id', $group_id); } )->when( $data['starttime_period'], function (Builder $query, $starttime_period) { // dd($starttime_period); if (isset($starttime_period['start']) && isset($starttime_period['end'])) { $from = Carbon::createFromDate($starttime_period['start']); $end = Carbon::createFromDate($starttime_period['end']); return $query ->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00')) ->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00')); } elseif (isset($starttime_period['start'])) { $from = Carbon::createFromDate($starttime_period['start']); return $query ->whereDate('starttime', '>=', $from->format('Y-m-d 00:00:00')); } elseif (isset($starttime_period['end'])) { $end = Carbon::createFromDate($starttime_period['end']); return $query ->whereDate('starttime', '<=', $end->format('Y-m-d 00:00:00')); } }); })->indicateUsing(function (): array { $indicators = []; if ($this->search_right) { $searchValues = preg_split('/\s+/', $this->search_right, -1, PREG_SPLIT_NO_EMPTY); foreach ($searchValues as $value) { $indicators[] = Indicator::make($value)->removeField($value); } } return $indicators; }) ->columns(4)->columnSpan(4), ], layout: FiltersLayout::AboveContent) // IconColumn::make('search_home')->icon('phosphor-magnifying-magnifying')->label('')->color('home')->width(30), // IconColumn::make('search_away')->icon('phosphor-magnifying-glass')->label('')->color('away')->width(30), // ->hiddenFilterIndicators() ->defaultPaginationPageOption(10) ->persistFiltersInSession() ->filtersFormColumns(3) ->deferFilters(false) ->toolbarActions([ Action::make('refreshMapperRight') ->hiddenLabel() ->color('gray') ->icon('phosphor-x') ->size(Size::Small) ->action(function (Component $livewire) { $this->search_right = ''; $this->tableSearch = ''; // Clears the main search bar $livewire->fill(['tableSearch' => '']); $livewire->resetTableFiltersForm(); // Clears all filters $this->dispatch('refreshMapperRight'); // $this->dispatch('refreshMapperLeft'); }), ]); } public function toggle() { $this->elements_swopped = ! $this->elements_swopped; } #[On('search_right')] public function searchRight($str) { $this->search_right = $str; $this->dispatch('refreshMapperRight'); } 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); $this->search_right = ''; $this->search_left = ''; $this->dispatch('refreshMapperLeft'); $this->dispatch('refreshMapperRight'); }) ->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'); } }