// +---------------------------------------------------------------------- declare (strict_types = 1); namespace addon\articles\model; use think\model\concern\SoftDelete; use ywxapp\model\BaseModel; /** * 文章专题模型 * * 专题 = 人工策划的聚合页:把若干文章归到一个主题下, * 用于运营落地页(如「新手入门」「年度盘点」)。 */ class ArticleTopic extends BaseModel { use SoftDelete; protected $name = 'articles_topic'; protected $deleteTime = 'delete_at'; protected $defaultSoftDelete = 0; protected $autoWriteTimestamp = true; protected $createTime = 'create_at'; protected $updateTime = 'update_at'; protected $type = [ 'status' => 'integer', 'sort' => 'integer', ]; /** 启用中 */ public function scopeEnable($query) { $query->where('delete_at', 0)->where('status', 1); } /** * 专题下的文章(多对多) */ public function articles() { return $this->belongsToMany(Article::class, ArticleTopicArticle::class, 'aid', 'tid'); } /** * 按别名取启用专题 */ public static function enabledByAlias(string $alias) { return self::scope('enable')->where('alias', $alias)->find(); } public static function ensureSchema(): void { \addon\articles\library\ArticleSchema::ensure(); } }