Skip to content

Commit a67ad3b

Browse files
authored
Merge pull request #195 from mallardduck/fix-post-page-count
Fix page/post count bug
2 parents a2ff14d + 26a0ab1 commit a67ad3b

File tree

9 files changed

+183
-156
lines changed

9 files changed

+183
-156
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
os: [ubuntu-latest, windows-latest]
16-
php: [8.1]
16+
php: [8.2]
1717
laravel: [10.*]
1818
stability: [prefer-stable]
1919
include:

composer.lock

Lines changed: 154 additions & 146 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Classes/RenderNavItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static function render(array $item, string $class = ''): string
1111
$color = 'border-b border-b-secondary-500 text-secondary-500';
1212

1313
if ($item['type'] === 'page-link' || $item['type'] === 'page_link') {
14-
$page = SkyPlugin::get()->getModel('Post')::page()->find($item['data']['page_id']) ?? '';
14+
$page = SkyPlugin::get()->getModel('Post')::page()->whereDate('published_at', '<=', now())->find($item['data']['page_id']) ?? '';
1515
$activeClass = (request()->routeIs('page', $page)) ? $color : 'border-transparent';
1616

1717
return '<a class="' . $class . ' ' . $activeClass . '"

src/Filament/Resources/PageResource.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ public static function getNavigationLabel(): string
216216
return __('Pages');
217217
}
218218

219+
public static function getNavigationBadge(): ?string
220+
{
221+
return (string) SkyPlugin::get()->getModel('Post')::page()->count();
222+
}
223+
219224
public static function getActions(): array
220225
{
221226
$action = [

src/Filament/Resources/PostResource.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ public static function getNavigationLabel(): string
258258
return __('Posts');
259259
}
260260

261+
public static function getNavigationBadge(): ?string
262+
{
263+
return (string) SkyPlugin::get()->getModel('Post')::posts()->count();
264+
}
265+
261266
public static function getActions(): array
262267
{
263268
$action = [

src/Livewire/Page.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ class Page extends Component
1111

1212
public function mount(string $slug): void
1313
{
14-
$this->page = config('zeus-sky.models.Post')::where('slug', $slug)->page()->firstOrFail();
14+
$this->page = config('zeus-sky.models.Post')::query()
15+
->page()
16+
->where('slug', $slug)
17+
->whereDate('published_at', '<=', now())
18+
->firstOrFail();
1519
}
1620

1721
public function render(): View

src/Livewire/Posts.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public function render(): View
2222
->orderBy('published_at', 'desc')
2323
->get();
2424

25-
$pages = config('zeus-sky.models.Post')::page()
25+
$pages = config('zeus-sky.models.Post')::query()
26+
->page()
27+
->whereDate('published_at', '<=', now())
2628
->search($search)
2729
->with(['tags', 'author', 'media'])
2830
->forCategory($category)
@@ -33,8 +35,10 @@ public function render(): View
3335
$pages = $this->highlightSearchResults($pages, $search);
3436
$posts = $this->highlightSearchResults($posts, $search);
3537

36-
$recent = config('zeus-sky.models.Post')::posts()
38+
$recent = config('zeus-sky.models.Post')::query()
39+
->posts()
3740
->published()
41+
->whereDate('published_at', '<=', now())
3842
->with(['tags', 'author', 'media'])
3943
->limit(config('zeus-sky.recentPostsLimit'))
4044
->orderBy('published_at', 'desc')

src/Models/PostScope.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,15 @@ public function scopeRelated(Builder $query, Post $post): Builder
5252
*/
5353
public function scopePage(Builder $query): Builder
5454
{
55-
return $query->where('post_type', 'page')
56-
->whereDate('published_at', '<=', now());
55+
return $query->where('post_type', 'page');
5756
}
5857

5958
/**
6059
* @param Builder<Post> $query
6160
*/
6261
public function scopePosts(Builder $query): Builder
6362
{
64-
return $query->where('post_type', 'post')
65-
->whereDate('published_at', '<=', now());
63+
return $query->where('post_type', 'post');
6664
}
6765

6866
/**

src/SkyServiceProvider.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ private function bootFilamentNavigation(): void
9090
->label(__('Select Page'))
9191
->searchable()
9292
->options(function () {
93-
return SkyPlugin::get()->getModel('Post')::page()->pluck('title', 'id');
93+
return SkyPlugin::get()->getModel('Post')::query()
94+
->page()
95+
->whereDate('published_at', '<=', now())
96+
->pluck('title', 'id');
9497
}),
9598
],
9699
'page_link'

0 commit comments

Comments
 (0)