Skip to content

Commit

Permalink
switch model and LW to config
Browse files Browse the repository at this point in the history
  • Loading branch information
atmonshi committed Oct 4, 2023
1 parent 4d70009 commit f6e5408
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 29 deletions.
3 changes: 1 addition & 2 deletions src/Livewire/Faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LaraZeus\Sky\Livewire;

use Illuminate\View\View;
use LaraZeus\Sky\SkyPlugin;
use Livewire\Component;

class Faq extends Component
Expand All @@ -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'));
}
}
5 changes: 2 additions & 3 deletions src/Livewire/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LaraZeus\Sky\Livewire;

use Illuminate\View\View;
use LaraZeus\Sky\SkyPlugin;
use Livewire\Component;

class Library extends Component
Expand All @@ -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'));
}
}
3 changes: 1 addition & 2 deletions src/Livewire/LibraryItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LaraZeus\Sky\Livewire;

use Illuminate\View\View;
use LaraZeus\Sky\SkyPlugin;
use Livewire\Component;

class LibraryItem extends Component
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/Livewire/LibraryTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\View\View;
use LaraZeus\Sky\Models\Tag;
use LaraZeus\Sky\SkyPlugin;
use Livewire\Component;

class LibraryTag extends Component
Expand All @@ -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);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Livewire/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LaraZeus\Sky\Livewire;

use Illuminate\View\View;
use LaraZeus\Sky\SkyPlugin;
use Livewire\Component;

class Page extends Component
Expand All @@ -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
Expand All @@ -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'));
}
Expand Down
5 changes: 2 additions & 3 deletions src/Livewire/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LaraZeus\Sky\Livewire;

use Illuminate\View\View;
use LaraZeus\Sky\SkyPlugin;
use Livewire\Component;

class Post extends Component
Expand All @@ -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
Expand All @@ -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'));
}

Expand Down
11 changes: 5 additions & 6 deletions src/Livewire/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace LaraZeus\Sky\Livewire;

use Illuminate\View\View;
use LaraZeus\Sky\SkyPlugin;
use Livewire\Component;

class Posts extends Component
Expand All @@ -15,15 +14,15 @@ 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)
->published()
->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)
Expand All @@ -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'))
Expand All @@ -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'));
}
Expand Down
3 changes: 1 addition & 2 deletions src/Livewire/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\View\View;
use LaraZeus\Sky\Models\Tag;
use LaraZeus\Sky\SkyPlugin;
use Livewire\Component;

class Tags extends Component
Expand All @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<span title='" . __('post status') . "' class='$PostStatus->class'> " . $icon . " {$PostStatus->label}</span>";
Expand Down Expand Up @@ -122,6 +122,7 @@ protected function requirePassword(): Attribute

public function getContent(): string
{
//todo
return $this->parseContent(SkyPlugin::get()->getEditor()::render($this->content));
}

Expand Down
10 changes: 5 additions & 5 deletions src/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Post> */
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
Expand Down

0 comments on commit f6e5408

Please sign in to comment.