52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use EloquentFilter\Filterable;
|
|
use App\Casts\Storage;
|
|
|
|
class Article extends Model
|
|
{
|
|
use HasFactory;
|
|
use Filterable;
|
|
|
|
protected function serializeDate(\DateTimeInterface $date)
|
|
{
|
|
return $date->format('Y-m-d H:i:s');
|
|
}
|
|
|
|
protected $appends = ['tags'];
|
|
|
|
protected $casts = [
|
|
'created_at' => 'datetime:Y-m-d H:i:s',
|
|
'updated_at' => 'datetime:Y-m-d H:i:s',
|
|
'published_at' => 'datetime:Y-m-d H:i:s',
|
|
'is_enable' => 'boolean',
|
|
'is_recommend' => 'boolean',
|
|
'cover' => Storage::class,
|
|
];
|
|
|
|
protected $fillable = [
|
|
'title',
|
|
'content',
|
|
'cover',
|
|
'category',
|
|
't_ids',
|
|
'published_at',
|
|
'is_enable',
|
|
'is_recommend',
|
|
'sort',
|
|
'appendixes',
|
|
];
|
|
|
|
protected function tags():Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn($value) => $this->t_ids ? explode(',', $this->t_ids) : [],
|
|
);
|
|
}
|
|
}
|