REFERRAL_LEVEL::class, 'depth' => 'integer', ]; /** * 获取用户信息 * * @return BelongsTo */ public function user() { return $this->belongsTo('App\Models\User', 'user_id'); } /** * 获取关联用户信息 * * @return BelongsTo */ public function relatedUser() { return $this->belongsTo('App\Models\User', 'related_user_id'); } /** * 获取关系路径数组 * * @return array */ public function getPathArrayAttribute(): array { if (empty($this->path)) { return []; } return explode(',', $this->path); } /** * 判断是否为直接关系 * * @return bool */ public function isDirectRelation(): bool { return $this->level == REFERRAL_LEVEL::DIRECT; } }