hasMany(DistAppearancePublishList::class, 'dist_id', 'id'); } /** * 关联到 DistAppearance */ public function appearance() { return $this->belongsTo(DistAppearance::class, 'appearance_id', 'id'); } /** * 根据域名查找 Distributor 并加载关联数据 * * @param string $domain * @return self|null */ public static function findByDomainWithAppearances(string $domain) { return self::with('appearancePublishes') // 预加载关联数据 ->where('custom_domain', $domain) ->orWhere('secondary_domain', $domain) ->first(); } /** * 根据域名查找 Distributor(不加载关联数据) * * @param string $domain * @return self|null */ public static function findByDomain(string $domain) { return self::where('custom_domain', $domain) ->orWhere('secondary_domain', $domain) ->first(); // 只查找当前模型数据 } }