From e3701f1cc127a10f7f7f28cc1ab9608c442fcfb9 Mon Sep 17 00:00:00 2001 From: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> Date: Mon, 29 Dec 2025 03:50:05 +0530 Subject: [PATCH] [4.x] Add more relation type annotations (#1424) This pull request adds improved PHPDoc type annotations to several Eloquent relationship methods, enhancing static analysis and developer experience. These changes clarify the expected return types for relationships, making the codebase easier to understand and work with. Relationship method type annotations: * Added a detailed return type annotation to the `tenant` method in the `BelongsToTenant` trait, specifying the related model and the current class. * Added a detailed return type annotation to the `domains` method in the `HasDomains` trait, specifying the related model and the current class. * Added a detailed return type annotation to the `tenants` method in the `ResourceSyncing` class, specifying the related model and the current class. --- src/Database/Concerns/BelongsToTenant.php | 3 +++ src/Database/Concerns/HasDomains.php | 6 +++++- src/ResourceSyncing/ResourceSyncing.php | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Database/Concerns/BelongsToTenant.php b/src/Database/Concerns/BelongsToTenant.php index f26a7ff8..da5dc84a 100644 --- a/src/Database/Concerns/BelongsToTenant.php +++ b/src/Database/Concerns/BelongsToTenant.php @@ -17,6 +17,9 @@ trait BelongsToTenant { use FillsCurrentTenant; + /** + * @return BelongsTo<\Illuminate\Database\Eloquent\Model&\Stancl\Tenancy\Contracts\Tenant, $this> + */ public function tenant(): BelongsTo { return $this->belongsTo(config('tenancy.models.tenant'), Tenancy::tenantKeyColumn()); diff --git a/src/Database/Concerns/HasDomains.php b/src/Database/Concerns/HasDomains.php index ae3aed42..1c185a27 100644 --- a/src/Database/Concerns/HasDomains.php +++ b/src/Database/Concerns/HasDomains.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Stancl\Tenancy\Database\Concerns; +use Illuminate\Database\Eloquent\Relations\HasMany; use Stancl\Tenancy\Contracts\Domain; use Stancl\Tenancy\Tenancy; @@ -14,7 +15,10 @@ use Stancl\Tenancy\Tenancy; */ trait HasDomains { - public function domains() + /** + * @return HasMany<\Illuminate\Database\Eloquent\Model&\Stancl\Tenancy\Contracts\Domain, $this> + */ + public function domains(): HasMany { return $this->hasMany(config('tenancy.models.domain'), Tenancy::tenantKeyColumn()); } diff --git a/src/ResourceSyncing/ResourceSyncing.php b/src/ResourceSyncing/ResourceSyncing.php index 272b7bd7..7799e9ba 100644 --- a/src/ResourceSyncing/ResourceSyncing.php +++ b/src/ResourceSyncing/ResourceSyncing.php @@ -105,6 +105,9 @@ trait ResourceSyncing return true; } + /** + * @return BelongsToMany<\Illuminate\Database\Eloquent\Model&\Stancl\Tenancy\Database\Contracts\TenantWithDatabase, $this> + */ public function tenants(): BelongsToMany { return $this->morphToMany(config('tenancy.models.tenant'), 'tenant_resources', 'tenant_resources', 'resource_global_id', 'tenant_id', $this->getGlobalIdentifierKeyName())