1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 19:34:04 +00:00

Fix #998, centralize config used by BelongsToTenant and HasDomains

This commit is contained in:
Samuel Štancl 2022-11-10 16:03:13 +01:00
parent 942d79cbd7
commit dd0f03f742
14 changed files with 41 additions and 32 deletions

View file

@ -14,12 +14,12 @@ trait BelongsToTenant
{
public function tenant()
{
return $this->belongsTo(config('tenancy.tenant_model'), static::tenantIdColumn());
return $this->belongsTo(config('tenancy.models.tenant'), static::tenantIdColumn());
}
public static function tenantIdColumn(): string
{
return config('tenancy.single_db.tenant_id_column');
return config('tenancy.models.tenant_key_column');
}
public static function bootBelongsToTenant(): void

View file

@ -2,8 +2,6 @@
declare(strict_types=1);
// todo not sure if this should be in Database\
namespace Stancl\Tenancy\Database\Concerns;
use Stancl\Tenancy\Contracts\Domain;
@ -17,12 +15,12 @@ trait HasDomains
{
public function domains()
{
return $this->hasMany(config('tenancy.domain_model'), 'tenant_id');
return $this->hasMany(config('tenancy.models.domain'), 'tenant_id');
}
public function createDomain($data): Domain
{
$class = config('tenancy.domain_model');
$class = config('tenancy.models.domain');
if (! is_array($data)) {
$data = ['domain' => $data];

View file

@ -28,7 +28,7 @@ class Domain extends Model implements Contracts\Domain
public function tenant(): BelongsTo
{
return $this->belongsTo(config('tenancy.tenant_model'));
return $this->belongsTo(config('tenancy.models.tenant'));
}
protected $dispatchesEvents = [

View file

@ -18,7 +18,7 @@ class DomainTenantResolver extends Contracts\CachedTenantResolver
{
$domain = $args[0];
$tenant = config('tenancy.tenant_model')::query()
$tenant = config('tenancy.models.tenant')::query()
->whereHas('domains', fn (Builder $query) => $query->where('domain', $domain))
->with('domains')
->first();

View file

@ -97,7 +97,7 @@ class Tenancy
public static function model(): Tenant&Model
{
$class = config('tenancy.tenant_model');
$class = config('tenancy.models.tenant');
/** @var Tenant&Model $model */
$model = new $class;

View file

@ -54,9 +54,9 @@ class TenancyServiceProvider extends ServiceProvider
$this->app->singleton($bootstrapper);
}
// Bind the class in the tenancy.id_generator config to the UniqueIdentifierGenerator abstract.
if (! is_null($this->app['config']['tenancy.id_generator'])) {
$this->app->bind(Contracts\UniqueIdentifierGenerator::class, $this->app['config']['tenancy.id_generator']);
// Bind the class in the tenancy.models.id_generator config to the UniqueIdentifierGenerator abstract.
if (! is_null($this->app['config']['tenancy.models.id_generator'])) {
$this->app->bind(Contracts\UniqueIdentifierGenerator::class, $this->app['config']['tenancy.models.id_generator']);
}
$this->app->singleton(Commands\Migrate::class, function ($app) {