feat: add article and production modules

This commit is contained in:
2026-08-31 13:16:46 +08:00
parent ac3da246b2
commit 5c586a1a95
334 changed files with 34419 additions and 1 deletions
@@ -0,0 +1,93 @@
<?php
declare(strict_types=1);
namespace plugin\article\app\model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Content extends BaseModel
{
protected $table = 'article_content';
protected $fillable = [
'id',
'title',
'content_type',
'slug',
'category_id',
'channel',
'visibility',
'author',
'source',
'cover',
'seo_keywords',
'seo_title',
'seo_description',
'summary',
'content',
'status',
'is_top',
'is_recommend',
'allow_comment',
'sort',
'view_count',
'like_count',
'comment_count',
'favorite_count',
'published_at',
'offline_at',
'created_by',
'updated_by',
'created_at',
'updated_at',
'deleted_at',
];
protected $casts = [
'category_id' => 'integer',
'visibility' => 'integer',
'status' => 'integer',
'is_top' => 'integer',
'is_recommend' => 'integer',
'allow_comment' => 'integer',
'sort' => 'integer',
'view_count' => 'integer',
'like_count' => 'integer',
'comment_count' => 'integer',
'favorite_count' => 'integer',
'published_at' => 'integer',
'offline_at' => 'integer',
'created_at' => 'integer',
'updated_at' => 'integer',
'deleted_at' => 'integer',
];
protected $appends = ['tag_names', 'tag_ids', 'category_name', 'created_date', 'updated_date', 'created_name', 'updated_name'];
public function category(): BelongsTo
{
return $this->belongsTo(Category::class, 'category_id', 'id');
}
public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class, 'article_content_tag', 'content_id', 'tag_id');
}
public function getCategoryNameAttribute(): string
{
return $this->category?->name ?? '';
}
public function getTagNamesAttribute(): string
{
return $this->tags->pluck('name')->implode('、');
}
public function getTagIdsAttribute(): array
{
return $this->tags->pluck('id')->map(static fn($id) => is_numeric($id) ? (int)$id : $id)->values()->all();
}
}