where('type', static::TYPE_AREA); } /** * 此地区的上级地区 */ public function parent() { return $this->belongsTo(static::class, 'parent_id'); } /** * 确认此地区是否是省 * * @return bool */ public function isProvince(): bool { return $this->type === static::TYPE_PROVINCE; } /** * 确认此地区是否是市 * * @return bool */ public function isCity(): bool { return $this->type === static::TYPE_CITY; } /** * 确认此地区是否是区 * * @return bool */ public function isArea(): bool { return $this->type === static::TYPE_AREA; } /** * 获取当前地区的完整名称 * * @return string */ public function getFullNameAttribute() { if ($this->parent_id === null) { return $this->name; } return $this->parent->full_name . ' ' . $this->name; } }