Skip to content

Commit

Permalink
Merge pull request #113 from lara-zeus/fix-tag
Browse files Browse the repository at this point in the history
Fix tag count
  • Loading branch information
atmonshi authored Jun 23, 2023
2 parents 2e9c68a + d0c2822 commit 8b044d8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion resources/views/filament/columns/tag-counts.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div>
{{ $getRecord()->{$getRecord()->type}()->count() }}
{{ method_exists($getRecord(),$getRecord()->type) ? $getRecord()->{$getRecord()->type}()->count() : 0 }}
</div>
8 changes: 4 additions & 4 deletions src/Filament/Resources/PageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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')),
Expand Down Expand Up @@ -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([
Expand All @@ -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')),
Expand Down
8 changes: 4 additions & 4 deletions src/Filament/Resources/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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')),
Expand Down Expand Up @@ -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'))
Expand All @@ -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')),
Expand Down
23 changes: 13 additions & 10 deletions src/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,37 @@

namespace LaraZeus\Sky\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;

/**
* @property string $slug
* @property string $type
* @property string $name
*/
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 postsPublished()
public function tag(): MorphToMany
{
return $this->morphedByMany(config('zeus-sky.models.post'), 'taggable');
}

public function postsPublished(): MorphToMany
{
return $this->morphedByMany(config('zeus-sky.models.post'), 'taggable')->published();
}
Expand All @@ -47,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();

Expand Down

0 comments on commit 8b044d8

Please sign in to comment.