init
This commit is contained in:
68
app/Models/Article.php
Normal file
68
app/Models/Article.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user