forked from eatvio/eatvio-infra
make static analyz for blogPost
This commit is contained in:
@@ -10,6 +10,8 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
|
||||
/**
|
||||
* App\Models\BlogPost
|
||||
@@ -57,17 +59,22 @@ class BlogPost extends Model implements Viewable
|
||||
{
|
||||
use HasFactory, InteractsWithViews;
|
||||
|
||||
protected $withCount = [
|
||||
'likes',
|
||||
'comments',
|
||||
];
|
||||
// protected array $withCount = [
|
||||
// 'likes',
|
||||
// 'comments',
|
||||
// ];
|
||||
|
||||
public static function getWithLikesAndCommentsCount(): Builder
|
||||
{
|
||||
return self::withCount(['likes', 'comments']);
|
||||
}
|
||||
|
||||
public function tags(): MorphToMany
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
|
||||
public function author()
|
||||
public function author(): HasOneThrough
|
||||
{
|
||||
return $this
|
||||
->hasOneThrough(User::class, BlogPostAuthor::class, 'blog_post_id', 'id', 'id', 'user_id')
|
||||
@@ -90,7 +97,7 @@ class BlogPost extends Model implements Viewable
|
||||
return $this->hasMany(BlogPostLike::class);
|
||||
}
|
||||
|
||||
public function isLiked(): bool
|
||||
public function isLiked(): bool|int
|
||||
{
|
||||
$curUser = auth()->user();
|
||||
if ($curUser) {
|
||||
|
||||
Reference in New Issue
Block a user