From 04dbdcc01f8529032b514d31ac03f19dfd91c419 Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Sat, 24 Jun 2023 00:22:51 +0300 Subject: [PATCH 1/4] fix tag morphedByMany --- src/Models/Tag.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Models/Tag.php b/src/Models/Tag.php index e00e8f7..467a54d 100644 --- a/src/Models/Tag.php +++ b/src/Models/Tag.php @@ -2,6 +2,8 @@ namespace LaraZeus\Sky\Models; +use Illuminate\Database\Eloquent\Relations\MorphToMany; + /** * @property string $slug * @property string $type @@ -9,26 +11,26 @@ */ class Tag extends \Spatie\Tags\Tag { - public function posts() - { - return $this->morphedByMany(config('zeus-sky.models.post'), 'taggable'); - } - - public function library() + public function library(): MorphToMany { return $this->morphedByMany(config('zeus-sky.models.library'), 'taggable'); } - public function category() + public function category(): MorphToMany { return $this->morphedByMany(config('zeus-sky.models.post'), 'taggable'); } - public function faq() + public function faq(): MorphToMany { return $this->morphedByMany(config('zeus-sky.models.faq'), 'taggable'); } + public function tag(): MorphToMany + { + return $this->morphedByMany(config('zeus-sky.models.post'), 'taggable'); + } + public function postsPublished() { return $this->morphedByMany(config('zeus-sky.models.post'), 'taggable')->published(); From 9092e506e3a75e4246e9537cd784916c92d7b458 Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Sat, 24 Jun 2023 00:23:24 +0300 Subject: [PATCH 2/4] Update tag-counts.blade.php --- resources/views/filament/columns/tag-counts.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/filament/columns/tag-counts.blade.php b/resources/views/filament/columns/tag-counts.blade.php index 70af7c9..c7ab323 100644 --- a/resources/views/filament/columns/tag-counts.blade.php +++ b/resources/views/filament/columns/tag-counts.blade.php @@ -1,3 +1,3 @@
- {{ $getRecord()->{$getRecord()->type}()->count() }} + {{ $getRecord()->{$getRecord()->type}()->count() ?? 0 }}
\ No newline at end of file From dbdf7d316f6b940a173385b4995d450984ee3fac Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Sat, 24 Jun 2023 00:28:56 +0300 Subject: [PATCH 3/4] Update tag-counts.blade.php --- resources/views/filament/columns/tag-counts.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/filament/columns/tag-counts.blade.php b/resources/views/filament/columns/tag-counts.blade.php index c7ab323..c70c995 100644 --- a/resources/views/filament/columns/tag-counts.blade.php +++ b/resources/views/filament/columns/tag-counts.blade.php @@ -1,3 +1,3 @@
- {{ $getRecord()->{$getRecord()->type}()->count() ?? 0 }} + {{ method_exists($getRecord(),$getRecord()->type) ? $getRecord()->{$getRecord()->type}()->count() : 0 }}
\ No newline at end of file From d0c282274a5e6531d77bf78a495fbb8afedb6d9f Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Sat, 24 Jun 2023 00:39:48 +0300 Subject: [PATCH 4/4] fix for stan --- src/Filament/Resources/PageResource.php | 8 ++++---- src/Filament/Resources/PostResource.php | 8 ++++---- src/Models/Tag.php | 5 +++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Filament/Resources/PageResource.php b/src/Filament/Resources/PageResource.php index cdbdcae..4306951 100644 --- a/src/Filament/Resources/PageResource.php +++ b/src/Filament/Resources/PageResource.php @@ -22,9 +22,9 @@ use Filament\Tables\Filters\Filter; use Filament\Tables\Filters\SelectFilter; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; use LaraZeus\Sky\Filament\Resources\PageResource\Pages; +use LaraZeus\Sky\Models\Post; class PageResource extends SkyResource { @@ -79,7 +79,7 @@ public static function form(Form $form): Form ->hint(__('Write an excerpt for your post')), TextInput::make('slug') - ->unique(ignorable: fn (?Model $record): ?Model => $record) + ->unique(ignorable: fn (?Post $record): ?Post => $record) ->required() ->maxLength(255) ->label(__('Post Slug')), @@ -144,7 +144,7 @@ public static function table(Table $table): Table ->searchable(['status']) ->toggleable() ->view('zeus-sky::filament.columns.status-desc') - ->tooltip(fn (Model $record): string => $record->published_at->format('Y/m/d | H:i A')), + ->tooltip(fn (Post $record): string => $record->published_at->format('Y/m/d | H:i A')), ]) ->defaultSort('id', 'desc') ->actions([ @@ -154,7 +154,7 @@ public static function table(Table $table): Table ->color('warning') ->icon('heroicon-o-external-link') ->label(__('Open')) - ->url(fn (Model $record): string => route('page', ['slug' => $record])) + ->url(fn (Post $record): string => route('page', ['slug' => $record])) ->openUrlInNewTab(), DeleteAction::make('delete') ->label(__('Delete')), diff --git a/src/Filament/Resources/PostResource.php b/src/Filament/Resources/PostResource.php index 80bc3f9..28a8d43 100644 --- a/src/Filament/Resources/PostResource.php +++ b/src/Filament/Resources/PostResource.php @@ -25,9 +25,9 @@ use Filament\Tables\Filters\Filter; use Filament\Tables\Filters\SelectFilter; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; use LaraZeus\Sky\Filament\Resources\PostResource\Pages; +use LaraZeus\Sky\Models\Post; class PostResource extends SkyResource { @@ -84,7 +84,7 @@ public static function form(Form $form): Form ->hint(__('Write an excerpt for your post')), TextInput::make('slug') - ->unique(ignorable: fn (?Model $record): ?Model => $record) + ->unique(ignorable: fn (?Post $record): ?Post => $record) ->required() ->maxLength(255) ->label(__('Post Slug')), @@ -177,7 +177,7 @@ public static function table(Table $table): Table ->searchable(['status']) ->toggleable() ->view('zeus-sky::filament.columns.status-desc') - ->tooltip(fn (Model $record): string => $record->published_at->format('Y/m/d | H:i A')), + ->tooltip(fn (Post $record): string => $record->published_at->format('Y/m/d | H:i A')), SpatieTagsColumn::make('tags') ->label(__('Post Tags')) @@ -197,7 +197,7 @@ public static function table(Table $table): Table ->color('warning') ->icon('heroicon-o-external-link') ->label(__('Open')) - ->url(fn (Model $record): string => route('post', ['slug' => $record])) + ->url(fn (Post $record): string => route('post', ['slug' => $record])) ->openUrlInNewTab(), DeleteAction::make('delete') ->label(__('Delete')), diff --git a/src/Models/Tag.php b/src/Models/Tag.php index 467a54d..867ca4b 100644 --- a/src/Models/Tag.php +++ b/src/Models/Tag.php @@ -2,6 +2,7 @@ namespace LaraZeus\Sky\Models; +use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphToMany; /** @@ -31,7 +32,7 @@ public function tag(): MorphToMany return $this->morphedByMany(config('zeus-sky.models.post'), 'taggable'); } - public function postsPublished() + public function postsPublished(): MorphToMany { return $this->morphedByMany(config('zeus-sky.models.post'), 'taggable')->published(); } @@ -49,7 +50,7 @@ protected function generateSlug(string $locale): string return call_user_func($slugger, $this->getTranslation('name', $locale)); } - public static function findBySlug(string $slug, string $type = null, string $locale = null) + public static function findBySlug(string $slug, string $type = null, string $locale = null): Model { $locale = $locale ?? static::getLocale();