This commit is contained in:
salam committed 2026-07-14 12:56:24 +02:00
1 parent 68a1ec1769
commit 987d096928
8 files changed
+149 -154

No files matched your search

@@ -27,82 +27,73 @@ class SofaScoreTournamentsTable
{
return $table
->columns([
IconColumn::make('sport.icon')
->label('')
->grow(false)
->width(30)
->color(fn ($record) => $record->sport->color)
->icon(fn ($record) => $record->sport->icon)
->size(IconSize::Medium)
->tooltip(fn ($record) => $record->id)
->visibleFrom('lg'),
TextColumn::make('tournament_id')->sortable()->searchable(),
TextColumn::make('sport.name'),
TextColumn::make('sofascore_category.name')
->icon(fn ($record) => $record->sofascore_category->country->icon),
TextColumn::make('name')->searchable()->sortable(),
// ToggleColumn::make('enabled')->label('Enable'),
ToggleColumn::make('disabled')->label('Disable'),
IconColumn::make('sport.icon')
->label('')
->grow(false)
->width(30)
->color(fn($record) => $record->sport->color)
->icon(fn($record) => $record->sport->icon)
->size(IconSize::Medium)
->tooltip(fn($record) => $record->id)
->visibleFrom('lg'),
TextColumn::make('tournament_id')->sortable()->searchable(),
TextColumn::make('sport.name'),
TextColumn::make('sofascore_category.name')
->icon(fn($record) => $record->sofascore_category->country->icon),
TextColumn::make('name')->searchable()->sortable(),
ToggleColumn::make('enabled')->label('Enable'),
ToggleColumn::make('disabled')->label('Hidden'),
])
->filters([
Filter::make('filters')
->columns(7)->columnSpan(7)
->schema([
Select::make('sport_id')
->default(1)
->selectablePlaceholder(false)
->label('Sport')
->options(Sport::where('is_active', 1)->pluck('name', 'id'))
->afterStateUpdated(function (callable $set) {
$set('sofa_score_categorie_id', null);
})
->live(),
Select::make('sofa_score_categorie_id')
->searchable()
->multiple()
->columnSpan(2)
->label('Categorie')
->options(function (Get $get) {
$res = SofaScoreTournament::where('sport_id', $get('sport_id'))
->groupBy('sofa_score_categorie_id')
->pluck('sofa_score_categorie_id')
->toArray();
Filter::make('filters')
->columns(7)->columnSpan(7)
->schema([
Select::make('sport_id')
->default(1)
->selectablePlaceholder(false)
->label('Sport')
->options(Sport::where('is_active', 1)->pluck('name', 'id'))
->afterStateUpdated(function (callable $set) {
$set('sofa_score_categorie_id', null);
})
->live(),
Select::make('sofa_score_categorie_id')
->searchable()
->multiple()
->columnSpan(2)
->label('Categorie')
->options(function (Get $get) {
$res = SofaScoreTournament::where('sport_id', $get('sport_id'))
->groupBy('sofa_score_categorie_id')
->pluck('sofa_score_categorie_id')
->toArray();
return SofaScoreCategorie::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
})
->live(),
// ToggleButtons::make('filter-grapping')
// ->inline()
// ->columnSpan(2)
// ->default('active')
// ->options([
// 'all' => 'All',
// 'active' => 'Active',
// 'disabled' => 'Disabled',
// ]),
ToggleButtons::make('filter-disabled')
->inline()
->columnSpan(2)
->default('active')
->options([
'all' => 'All',
'active' => 'Active',
'hidden' => 'Hidden',
]),
])
->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['sofa_score_categorie_id'],
function (Builder $query, $sofa_score_categorie_id) {
if (is_array($sofa_score_categorie_id)) {
$query->whereIn('sofa_score_categorie_id', $sofa_score_categorie_id);
} else {
$query->where('sofa_score_categorie_id', $sofa_score_categorie_id);
}
return SofaScoreCategorie::query()->whereIn('id', $res)->orderBy('name')->pluck('name', 'id');
})
->live(),
ToggleButtons::make('filter-disabled')
->inline()
->columnSpan(2)
->default('active')
->options([
'all' => 'All',
'enabled' => 'Enabled',
'hidden' => 'Hidden',
]),
])
->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['sofa_score_categorie_id'],
function (Builder $query, $sofa_score_categorie_id) {
if (is_array($sofa_score_categorie_id)) {
$query->whereIn('sofa_score_categorie_id', $sofa_score_categorie_id);
} else {
$query->where('sofa_score_categorie_id', $sofa_score_categorie_id);
}
}
// )->when(
// $data['filter-grapping'],
// function (Builder $query, $filtergrapping) {
@@ -115,71 +106,71 @@ class SofaScoreTournamentsTable
// break;
// }
// }
)->when(
$data['filter-disabled'],
function (Builder $query, $filterdisabled) {
switch ($filterdisabled) {
case 'active':
$query->where('disabled', 0);
break;
case 'hidden':
$query->where('disabled', 1);
break;
}
)->when(
$data['filter-disabled'],
function (Builder $query, $filterdisabled) {
switch ($filterdisabled) {
case 'enabled':
$query->where('enabled', 1);
break;
case 'hidden':
$query->where('disabled', 1);
break;
}
);
}),
}
);
}),
], layout: FiltersLayout::AboveContent)
->deferFilters(false)
->toolbarActions([
BulkActionGroup::make([
BulkAction::make('Enable')
->icon('phosphor-toggle-right-fill')
->color('primary')
->action(function (Collection $records): void {
foreach ($records as $record) {
SofaScoreTournament::where('id', '=', $record->id)
->update(
['enabled' => 1]
);
}
}),
BulkAction::make('Disable')
->icon('phosphor-toggle-left-fill')
->color('gray')
->action(function (Collection $records): void {
foreach ($records as $record) {
SofaScoreTournament::where('id', '=', $record->id)
->update(
['enabled' => 0]
);
}
}),
BulkAction::make('Enable selected')
->icon('phosphor-toggle-right-fill')
->color('primary')
->action(function (Collection $records): void {
foreach ($records as $record) {
SofaScoreTournament::where('id', '=', $record->id)
->update(
['enabled' => 1]
);
}
}),
BulkAction::make('Disable selected')
->icon('phosphor-toggle-left-fill')
->color('gray')
->action(function (Collection $records): void {
foreach ($records as $record) {
SofaScoreTournament::where('id', '=', $record->id)
->update(
['enabled' => 0]
);
}
}),
])->label('Grapping'),
BulkActionGroup::make([
BulkAction::make('Hide')
->icon('phosphor-toggle-right-fill')
->color('primary')
->action(function (Collection $records): void {
foreach ($records as $record) {
SofaScoreTournament::where('id', '=', $record->id)
->update(
['disabled' => 1]
);
}
}),
BulkAction::make('Show')
->icon('phosphor-toggle-left-fill')
->color('gray')
->action(function (Collection $records): void {
foreach ($records as $record) {
SofaScoreTournament::where('id', '=', $record->id)
->update(
['disabled' => 0]
);
}
}),
])->label('Disabled'),
BulkAction::make('Hide selected')
->icon('phosphor-toggle-right-fill')
->color('primary')
->action(function (Collection $records): void {
foreach ($records as $record) {
SofaScoreTournament::where('id', '=', $record->id)
->update(
['disabled' => 1]
);
}
}),
BulkAction::make('Show selected')
->icon('phosphor-toggle-left-fill')
->color('gray')
->action(function (Collection $records): void {
foreach ($records as $record) {
SofaScoreTournament::where('id', '=', $record->id)
->update(
['disabled' => 0]
);
}
}),
])->label('Hidden'),
]);
}
}