catchSearch() ->field($this->aliasField('*')) ->catchJoin(Category::class, 'id', 'category_id', ['name as category']) ->catchOrder() ->creator() ->paginate(); } /** * 查询 * * @auth CatchAdmin * @time 2021年05月22日 * @param $id * @param array|string[] $field * @param bool $trash * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @return array|mixed|\think\Model|null */ public function findBy($id, array $field = ['*'], bool $trash = false) { return $this->where('id', $id) ->with(['tag']) ->field('*') ->find(); } /** * 文章标签 * * @time 2021年05月17日 * @return \think\model\relation\BelongsToMany */ public function tag(): \think\model\relation\BelongsToMany { return $this->belongsToMany(Tags::class, 'cms_article_relate_tags', 'tag_id', 'article_id' ); } /** * 删除标签 * * @param array $ids * @return int * @author CatchAdmin * @time 2021年05月22日 */ public function detachTags(array $ids = []): int { return $this->tag()->detach($ids); } /** * 新增标签 * * @author CatchAdmin * @time 2021年05月22日 * @param array $ids * @throws \think\db\exception\DbException * @return array|\think\model\Pivot */ public function attachTags(array $ids) { return $this->tag()->attach($ids); } /** * 文章评论 * * @time 2021年05月27日 * @return \think\model\relation\HasMany */ public function comments(): \think\model\relation\HasMany { return $this->hasMany(Comments::class, 'article_id', 'id'); } }