Files
ai-web/app/Models/Article.php

69 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2026-02-11 17:28:36 +08:00
<?php
declare(strict_types=1);
namespace App\Models;
use App\Enums\EntityStatus;
use App\Enums\SourceLevel;
use App\Models\Concerns\HasPublicationScope;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Article extends Model
{
use HasFactory;
use HasPublicationScope;
protected $fillable = [
'category_id',
'source_id',
'title',
'slug',
'excerpt',
'body',
'source_name',
'source_url',
'source_level',
'last_verified_at',
'status',
'is_stale',
'stale_note',
'seo_title',
'seo_description',
'h1',
'canonical_url',
'published_at',
];
protected function casts(): array
{
return [
'published_at' => 'datetime',
'last_verified_at' => 'datetime',
'is_stale' => 'boolean',
'source_level' => SourceLevel::class,
'status' => EntityStatus::class,
];
}
public function category(): BelongsTo
{
return $this->belongsTo(Category::class);
}
public function source(): BelongsTo
{
return $this->belongsTo(Source::class);
}
public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class, 'entity_tag_maps', 'entity_id', 'tag_id')
->wherePivot('entity_type', self::class)
->withTimestamps();
}
}