belongsTo(Menu::class, 'parent_id'); } public function children() { return $this->hasMany(Menu::class, 'parent_id'); } /** * 공유(NULL) + 현재 테넌트 모두 포함해서 조회 * (SoftDeletes 글로벌 스코프는 그대로 유지) */ public function scopeWithShared($query, ?int $tenantId = null) { $tenantId = $tenantId ?? app('tenant_id'); return $query ->withoutGlobalScope(TenantScope::class) ->where(function ($w) use ($tenantId) { if (is_null($tenantId)) { $w->whereNull('tenant_id'); } else { $w->whereNull('tenant_id')->orWhere('tenant_id', $tenantId); } }); } }