Skip to content

Commit f0efe11

Browse files
committed
tidy - improve filament article sorting
1 parent 00f083d commit f0efe11

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

app/Filament/Resources/ArticleResource.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Filament\Tables\Actions\ActionGroup;
1717
use Filament\Tables\Columns\TextColumn;
1818
use Filament\Tables\Table;
19+
use Illuminate\Contracts\Database\Eloquent\Builder;
1920
use Illuminate\Support\Str;
2021

2122
class ArticleResource extends Resource
@@ -72,10 +73,12 @@ public static function table(Table $table): Table
7273
->sortable(),
7374

7475
TextColumn::make('published_at')
75-
->dateTime('M j, Y H:i')
76-
->sortable()
7776
->badge()
78-
->color(fn ($state) => $state && $state->isPast() ? 'success' : 'warning'),
77+
->dateTime('M j, Y H:i')
78+
->color(fn ($state) => $state && $state->isPast() ? 'success' : 'warning')
79+
->sortable(query: function (Builder $query, string $direction): Builder {
80+
return $query->orderByRaw("published_at IS NULL {$direction}, published_at {$direction}");
81+
}),
7982
])
8083
->filters([
8184
//

0 commit comments

Comments
 (0)