Skip to content

Commit

Permalink
separate the published_at from the page and posts scope
Browse files Browse the repository at this point in the history
  • Loading branch information
atmonshi committed Mar 5, 2024
1 parent 019a5cf commit 26a0ab1
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 158 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.1]
php: [8.2]
laravel: [10.*]
stability: [prefer-stable]
include:
Expand Down
300 changes: 154 additions & 146 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Classes/RenderNavItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static function render(array $item, string $class = ''): string
$color = 'border-b border-b-secondary-500 text-secondary-500';

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

return '<a class="' . $class . ' ' . $activeClass . '"
Expand Down
2 changes: 1 addition & 1 deletion src/Filament/Resources/PageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static function getNavigationLabel(): string

public static function getNavigationBadge(): ?string
{
return (string) static::getEloquentQuery()->page()->count();
return (string) SkyPlugin::get()->getModel('Post')::page()->count();
}

public static function getActions(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Filament/Resources/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public static function getNavigationLabel(): string

public static function getNavigationBadge(): ?string
{
return (string) static::getEloquentQuery()->posts()->count();
return (string) SkyPlugin::get()->getModel('Post')::posts()->count();
}

public static function getActions(): array
Expand Down
6 changes: 5 additions & 1 deletion src/Livewire/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class Page extends Component

public function mount(string $slug): void
{
$this->page = config('zeus-sky.models.Post')::where('slug', $slug)->page()->firstOrFail();
$this->page = config('zeus-sky.models.Post')::query()
->page()
->where('slug', $slug)
->whereDate('published_at', '<=', now())
->firstOrFail();
}

public function render(): View
Expand Down
8 changes: 6 additions & 2 deletions src/Livewire/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public function render(): View
->orderBy('published_at', 'desc')
->get();

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

$recent = config('zeus-sky.models.Post')::posts()
$recent = config('zeus-sky.models.Post')::query()
->posts()
->published()
->whereDate('published_at', '<=', now())
->with(['tags', 'author', 'media'])
->limit(config('zeus-sky.recentPostsLimit'))
->orderBy('published_at', 'desc')
Expand Down
6 changes: 2 additions & 4 deletions src/Models/PostScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@ public function scopeRelated(Builder $query, Post $post): Builder
*/
public function scopePage(Builder $query): Builder
{
return $query->where('post_type', 'page')
->whereDate('published_at', '<=', now());
return $query->where('post_type', 'page');
}

/**
* @param Builder<Post> $query
*/
public function scopePosts(Builder $query): Builder
{
return $query->where('post_type', 'post')
->whereDate('published_at', '<=', now());
return $query->where('post_type', 'post');
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/SkyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ private function bootFilamentNavigation(): void
->label(__('Select Page'))
->searchable()
->options(function () {
return SkyPlugin::get()->getModel('Post')::page()->pluck('title', 'id');
return SkyPlugin::get()->getModel('Post')::query()
->page()
->whereDate('published_at', '<=', now())
->pluck('title', 'id');
}),
],
'page_link'
Expand Down

0 comments on commit 26a0ab1

Please sign in to comment.