Skip to content

Commit 6960fb7

Browse files
author
thapacodes4u
committed
fix: section filter now persists when toggling columns
1 parent 02a769e commit 6960fb7

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

src/Admin/Filament/Resources/PageResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public static function table(Table $table): Table
183183
->sortable()
184184
->badge()
185185
->color('gray')
186-
->hidden(fn () => request()->has('sId')),
186+
->visible(fn ($livewire): bool => ! ($livewire instanceof Pages\ListPages && $livewire->sectionId)),
187187

188188
TextColumn::make('sef_key')
189189
->label('URL Slug')

src/Admin/Filament/Resources/PageResource/Pages/ListPages.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,19 @@ class ListPages extends ListRecords
1515

1616
protected static string $resource = PageResource::class;
1717

18+
public ?int $sectionId = null;
19+
20+
public function mount(): void
21+
{
22+
parent::mount();
23+
24+
$this->sectionId = request()->get('sId');
25+
}
26+
1827
public function getTitle(): string
1928
{
20-
if ($sectionId = request()->get('sId')) {
21-
$section = Section::find($sectionId);
29+
if ($this->sectionId) {
30+
$section = Section::find($this->sectionId);
2231
if ($section) {
2332
return $section->name;
2433
}
@@ -29,8 +38,8 @@ public function getTitle(): string
2938

3039
public function getBreadcrumb(): ?string
3140
{
32-
if ($sectionId = request()->get('sId')) {
33-
$section = Section::find($sectionId);
41+
if ($this->sectionId) {
42+
$section = Section::find($this->sectionId);
3443
if ($section) {
3544
return $section->name;
3645
}
@@ -43,8 +52,8 @@ protected function getTableQuery(): Builder
4352
{
4453
$query = parent::getTableQuery();
4554

46-
if ($sectionId = request()->get('sId')) {
47-
$query->where('section_id', $sectionId);
55+
if ($this->sectionId) {
56+
$query->where('section_id', $this->sectionId);
4857
}
4958

5059
return $query;
@@ -54,10 +63,10 @@ protected function getHeaderActions(): array
5463
{
5564
$createAction = CreateAction::make();
5665

57-
if (request()->get('sId')) {
66+
if ($this->sectionId) {
5867
$createAction
5968
->url(fn () => PageResource::getUrl('create', [
60-
'sId' => request()->get('sId'),
69+
'sId' => $this->sectionId,
6170
]));
6271
}
6372

0 commit comments

Comments
 (0)