mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 19:44:04 +00:00
35 lines
725 B
PHP
35 lines
725 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
// todo not sure if this should be in Database\
|
|
|
|
namespace Stancl\Tenancy\Database\Concerns;
|
|
|
|
use Stancl\Tenancy\Contracts\Domain;
|
|
|
|
/**
|
|
* @property-read Domain[]|\Illuminate\Database\Eloquent\Collection $domains
|
|
*/
|
|
trait HasDomains
|
|
{
|
|
public function domains()
|
|
{
|
|
return $this->hasMany(config('tenancy.domain_model'), 'tenant_id');
|
|
}
|
|
|
|
public function createDomain($data): Domain
|
|
{
|
|
$class = config('tenancy.domain_model');
|
|
|
|
if (! is_array($data)) {
|
|
$data = ['domain' => $data];
|
|
}
|
|
|
|
$domain = (new $class)->fill($data);
|
|
$domain->tenant()->associate($this);
|
|
$domain->save();
|
|
|
|
return $domain;
|
|
}
|
|
}
|