From f6e54088fac5eb52faf25c131bdfd590dfe6525c Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Wed, 4 Oct 2023 18:05:44 +0300 Subject: [PATCH] switch model and LW to config --- src/Livewire/Faq.php | 3 +-- src/Livewire/Library.php | 5 ++--- src/Livewire/LibraryItem.php | 3 +-- src/Livewire/LibraryTag.php | 3 +-- src/Livewire/Page.php | 5 ++--- src/Livewire/Post.php | 5 ++--- src/Livewire/Posts.php | 11 +++++------ src/Livewire/Tags.php | 3 +-- src/Models/Post.php | 3 ++- src/Models/Tag.php | 10 +++++----- 10 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/Livewire/Faq.php b/src/Livewire/Faq.php index 4083499..7559096 100644 --- a/src/Livewire/Faq.php +++ b/src/Livewire/Faq.php @@ -3,7 +3,6 @@ namespace LaraZeus\Sky\Livewire; use Illuminate\View\View; -use LaraZeus\Sky\SkyPlugin; use Livewire\Component; class Faq extends Component @@ -20,7 +19,7 @@ public function render(): View ->twitter(); return view(app('skyTheme') . '.addons.faq') - ->with('faqs', SkyPlugin::get()->getModel('Faq')::get()) + ->with('faqs', config('zeus-sky.models.faq')::get()) ->layout(config('zeus.layout')); } } diff --git a/src/Livewire/Library.php b/src/Livewire/Library.php index 433536c..1b16e79 100644 --- a/src/Livewire/Library.php +++ b/src/Livewire/Library.php @@ -3,7 +3,6 @@ namespace LaraZeus\Sky\Livewire; use Illuminate\View\View; -use LaraZeus\Sky\SkyPlugin; use Livewire\Component; class Library extends Component @@ -20,8 +19,8 @@ public function render(): View ->twitter(); return view(app('skyTheme') . '.addons.library') - ->with('libraries', SkyPlugin::get()->getModel('Library')::get()) - ->with('categories', SkyPlugin::get()->getModel('Tag')::getWithType('library')) + ->with('libraries', config('zeus-sky.models.Library')::get()) + ->with('categories', config('zeus-sky.models.Tag')::getWithType('library')) ->layout(config('zeus.layout')); } } diff --git a/src/Livewire/LibraryItem.php b/src/Livewire/LibraryItem.php index 12a40a1..3324907 100644 --- a/src/Livewire/LibraryItem.php +++ b/src/Livewire/LibraryItem.php @@ -3,7 +3,6 @@ namespace LaraZeus\Sky\Livewire; use Illuminate\View\View; -use LaraZeus\Sky\SkyPlugin; use Livewire\Component; class LibraryItem extends Component @@ -12,7 +11,7 @@ class LibraryItem extends Component public function mount(string $slug): void { - $this->item = SkyPlugin::get()->getModel('Library')::where('slug', $slug)->firstOrFail(); + $this->item = config('zeus-sky.models.Library')::where('slug', $slug)->firstOrFail(); } public function render(): View diff --git a/src/Livewire/LibraryTag.php b/src/Livewire/LibraryTag.php index ef90d44..393ebf9 100644 --- a/src/Livewire/LibraryTag.php +++ b/src/Livewire/LibraryTag.php @@ -4,7 +4,6 @@ use Illuminate\View\View; use LaraZeus\Sky\Models\Tag; -use LaraZeus\Sky\SkyPlugin; use Livewire\Component; class LibraryTag extends Component @@ -13,7 +12,7 @@ class LibraryTag extends Component public function mount(string $slug): void { - $this->tag = SkyPlugin::get()->getModel('Tag')::findBySlug($slug, 'library'); + $this->tag = config('zeus-sky.models.Tag')::findBySlug($slug, 'library'); abort_if($this->tag === null, 404); } diff --git a/src/Livewire/Page.php b/src/Livewire/Page.php index 47a2166..4126e7e 100644 --- a/src/Livewire/Page.php +++ b/src/Livewire/Page.php @@ -3,7 +3,6 @@ namespace LaraZeus\Sky\Livewire; use Illuminate\View\View; -use LaraZeus\Sky\SkyPlugin; use Livewire\Component; class Page extends Component @@ -12,7 +11,7 @@ class Page extends Component public function mount(string $slug): void { - $this->page = SkyPlugin::get()->getModel('Post')::where('slug', $slug)->page()->firstOrFail(); + $this->page = config('zeus-sky.models.Post')::where('slug', $slug)->page()->firstOrFail(); } public function render(): View @@ -33,7 +32,7 @@ public function render(): View return view(app('skyTheme') . '.page') ->with([ 'post' => $this->page, - 'children' => SkyPlugin::get()->getModel('Post')::with('parent')->where('parent_id', $this->page->id)->get(), + 'children' => config('zeus-sky.models.Post')::with('parent')->where('parent_id', $this->page->id)->get(), ]) ->layout(config('zeus.layout')); } diff --git a/src/Livewire/Post.php b/src/Livewire/Post.php index e977db1..3bfde6e 100644 --- a/src/Livewire/Post.php +++ b/src/Livewire/Post.php @@ -3,7 +3,6 @@ namespace LaraZeus\Sky\Livewire; use Illuminate\View\View; -use LaraZeus\Sky\SkyPlugin; use Livewire\Component; class Post extends Component @@ -12,7 +11,7 @@ class Post extends Component public function mount(string $slug): void { - $this->post = SkyPlugin::get()->getModel('Post')::where('slug', $slug)->firstOrFail(); + $this->post = config('zeus-sky.models.Post')::where('slug', $slug)->firstOrFail(); } public function render(): View @@ -31,7 +30,7 @@ public function render(): View return view(app('skyTheme') . '.post') ->with('post', $this->post) - ->with('related', SkyPlugin::get()->getModel('Post')::related($this->post)->take(4)->get()) + ->with('related', config('zeus-sky.models.Post')::related($this->post)->take(4)->get()) ->layout(config('zeus.layout')); } diff --git a/src/Livewire/Posts.php b/src/Livewire/Posts.php index efc1940..df0e2a0 100644 --- a/src/Livewire/Posts.php +++ b/src/Livewire/Posts.php @@ -3,7 +3,6 @@ namespace LaraZeus\Sky\Livewire; use Illuminate\View\View; -use LaraZeus\Sky\SkyPlugin; use Livewire\Component; class Posts extends Component @@ -15,7 +14,7 @@ public function render(): View $search = request('search'); $category = request('category'); - $posts = SkyPlugin::get()->getModel('Post')::NotSticky() + $posts = config('zeus-sky.models.Post')::NotSticky() ->search($search) ->with(['tags', 'author', 'media']) ->forCategory($category) @@ -23,7 +22,7 @@ public function render(): View ->orderBy('published_at', 'desc') ->get(); - $pages = SkyPlugin::get()->getModel('Post')::page() + $pages = config('zeus-sky.models.Post')::page() ->search($search) ->with(['tags', 'author', 'media']) ->forCategory($category) @@ -34,7 +33,7 @@ public function render(): View $pages = $this->highlightSearchResults($pages, $search); $posts = $this->highlightSearchResults($posts, $search); - $recent = SkyPlugin::get()->getModel('Post')::posts() + $recent = config('zeus-sky.models.Post')::posts() ->published() ->with(['tags', 'author', 'media']) ->limit(config('zeus-sky.recentPostsLimit')) @@ -55,10 +54,10 @@ public function render(): View 'posts' => $posts, 'pages' => $pages, 'recent' => $recent, - 'tags' => SkyPlugin::get()->getModel('Tag')::withCount('postsPublished') + 'tags' => config('zeus-sky.models.Tag')::withCount('postsPublished') ->where('type', 'category') ->get(), - 'stickies' => SkyPlugin::get()->getModel('Post')::with(['author', 'media'])->sticky()->published()->get(), + 'stickies' => config('zeus-sky.models.Post')::with(['author', 'media'])->sticky()->published()->get(), ]) ->layout(config('zeus.layout')); } diff --git a/src/Livewire/Tags.php b/src/Livewire/Tags.php index 7bb3e9b..f5c8f5f 100644 --- a/src/Livewire/Tags.php +++ b/src/Livewire/Tags.php @@ -4,7 +4,6 @@ use Illuminate\View\View; use LaraZeus\Sky\Models\Tag; -use LaraZeus\Sky\SkyPlugin; use Livewire\Component; class Tags extends Component @@ -19,7 +18,7 @@ public function mount(string $type, string $slug): void { $this->type = $type; $this->slug = $slug; - $this->tag = SkyPlugin::get()->getModel('Tag')::findBySlug($slug, $type); + $this->tag = config('zeus-sky.models.Tag')::findBySlug($slug, $type); abort_if($this->tag === null, 404); } diff --git a/src/Models/Post.php b/src/Models/Post.php index e55cd7b..88ec8ca 100644 --- a/src/Models/Post.php +++ b/src/Models/Post.php @@ -83,7 +83,7 @@ public function getRouteKeyName() public function statusDesc(): string { - $PostStatus = SkyPlugin::get()->getModel('PostStatus')::where('name', $this->status)->first(); + $PostStatus = config('zeus-sky.models.PostStatus')::where('name', $this->status)->first(); $icon = Blade::render('@svg("' . $PostStatus->icon . '","w-4 h-4 inline-flex")'); return " " . $icon . " {$PostStatus->label}"; @@ -122,6 +122,7 @@ protected function requirePassword(): Attribute public function getContent(): string { + //todo return $this->parseContent(SkyPlugin::get()->getEditor()::render($this->content)); } diff --git a/src/Models/Tag.php b/src/Models/Tag.php index 5149f63..313ce0f 100644 --- a/src/Models/Tag.php +++ b/src/Models/Tag.php @@ -19,29 +19,29 @@ class Tag extends \Spatie\Tags\Tag { public function library(): MorphToMany { - return $this->morphedByMany(SkyPlugin::get()->getModel('Library'), 'taggable'); + return $this->morphedByMany(config('zeus-sky.models.Library'), 'taggable'); } public function category(): MorphToMany { - return $this->morphedByMany(SkyPlugin::get()->getModel('Post'), 'taggable'); + return $this->morphedByMany(config('zeus-sky.models.Post'), 'taggable'); } public function faq(): MorphToMany { - return $this->morphedByMany(SkyPlugin::get()->getModel('Faq'), 'taggable'); + return $this->morphedByMany(config('zeus-sky.models.Faq'), 'taggable'); } public function tag(): MorphToMany { - return $this->morphedByMany(SkyPlugin::get()->getModel('Post'), 'taggable'); + return $this->morphedByMany(config('zeus-sky.models.Post'), 'taggable'); } /** @return MorphToMany */ public function postsPublished(): MorphToMany { // @phpstan-ignore-next-line - return $this->morphedByMany(SkyPlugin::get()->getModel('Post'), 'taggable')->published(); + return $this->morphedByMany(config('zeus-sky.models.Post'), 'taggable')->published(); } protected function generateSlug(string $locale): string