// +---------------------------------------------------------------------- declare (strict_types = 1); namespace addon\docs\model; use think\Model; /** * 文档项目模型 * * @author ywxapp */ class DocsProject extends Model { protected $name = 'docs_project'; protected $autoWriteTimestamp = true; protected $createTime = 'create_at'; protected $updateTime = 'update_at'; protected $type = [ 'id' => 'integer', 'owner_uid' => 'integer', 'sort' => 'integer', 'status' => 'integer', ]; /** * 关联版本列表 */ public function versions() { return $this->hasMany(DocsVersion::class, 'project_id', 'id') ->order('sort', 'asc') ->order('id', 'asc'); } /** * 按 URL 标识获取启用中的项目 * * @param string $name 项目标识 * @return static|null */ public static function findByName(string $name) { if ($name === '') { return null; } return static::where('name', $name)->where('status', 1)->find(); } /** * 获取全部启用项目(按排序) * * @return \think\Collection */ public static function enabledList() { return static::where('status', 1) ->order('sort', 'asc') ->order('id', 'asc') ->select(); } }