1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 17:04:04 +00:00
tenancy/src/Database/Concerns/HasDomains.php
Punyapal Shah e3701f1cc1
[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.
2025-12-28 23:20:05 +01:00

40 lines
987 B
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Stancl\Tenancy\Contracts\Domain;
use Stancl\Tenancy\Tenancy;
/**
* @property-read Domain[]|\Illuminate\Database\Eloquent\Collection $domains
* @mixin \Illuminate\Database\Eloquent\Model
* @mixin \Stancl\Tenancy\Contracts\Tenant
*/
trait HasDomains
{
/**
* @return HasMany<\Illuminate\Database\Eloquent\Model&\Stancl\Tenancy\Contracts\Domain, $this>
*/
public function domains(): HasMany
{
return $this->hasMany(config('tenancy.models.domain'), Tenancy::tenantKeyColumn());
}
public function createDomain($data): Domain
{
$class = config('tenancy.models.domain');
if (! is_array($data)) {
$data = ['domain' => $data];
}
$domain = (new $class)->fill($data);
$domain->tenant()->associate($this);
$domain->save();
return $domain;
}
}