format('Y-m-d H:i:s'); } protected $appends = ['tags']; protected $casts = [ 'published_at' => 'datetime', 'is_enable' => 'boolean', 'is_recommend' => 'boolean', 'appendixes' => 'array', ]; protected $fillable = [ 'title', 'content', 'cover', 'category', 't_ids', 'published_at', 'is_enable', 'is_recommend', 'sort', 'appendixes', 'source' ]; public function scopeShow($q){ $q->where('is_enable', true)->where('published_at', '<=', now()); } public function scopeSort($q) { $q->orderBy('is_recommend', 'desc') ->orderBy('sort', 'asc') ->orderBy('published_at', 'desc') ->orderBy('created_at', 'desc'); } protected function tags():Attribute { return Attribute::make( get: fn($value) => $this->t_ids ? explode(',', $this->t_ids) : [], ); } }