mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 19:14:04 +00:00
fix phpstan errors
This commit is contained in:
parent
18a16e6a74
commit
4372e1bef2
20 changed files with 105 additions and 16 deletions
10
phpstan.neon
10
phpstan.neon
|
|
@ -14,8 +14,11 @@ parameters:
|
||||||
- Illuminate\Database\Eloquent\Model
|
- Illuminate\Database\Eloquent\Model
|
||||||
|
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
|
-
|
||||||
|
identifier: missingType.iterableValue
|
||||||
- '#Cannot access offset (.*?) on Illuminate\\Contracts\\Foundation\\Application#'
|
- '#Cannot access offset (.*?) on Illuminate\\Contracts\\Foundation\\Application#'
|
||||||
- '#Cannot access offset (.*?) on Illuminate\\Contracts\\Config\\Repository#'
|
- '#Cannot access offset (.*?) on Illuminate\\Contracts\\Config\\Repository#'
|
||||||
|
- '#Call to an undefined method(.*?)Tenant\:\:run\(\).#'
|
||||||
-
|
-
|
||||||
message: '#Call to an undefined (method|static method) Illuminate\\Database\\Eloquent\\(Model|Builder)#'
|
message: '#Call to an undefined (method|static method) Illuminate\\Database\\Eloquent\\(Model|Builder)#'
|
||||||
paths:
|
paths:
|
||||||
|
|
@ -23,7 +26,10 @@ parameters:
|
||||||
- src/Commands/ClearPendingTenants.php
|
- src/Commands/ClearPendingTenants.php
|
||||||
- src/Database/Concerns/PendingScope.php
|
- src/Database/Concerns/PendingScope.php
|
||||||
- src/Database/ParentModelScope.php
|
- src/Database/ParentModelScope.php
|
||||||
- '#Call to an undefined method Illuminate\\Database\\Eloquent\\Builder\:\:withPending\(\)#'
|
-
|
||||||
|
message: '#Call to an undefined method Illuminate\\Database\\Eloquent\\Builder<Illuminate\\Database\\Eloquent\\Model&Stancl\\Tenancy\\Contracts\\Tenant>\:\:withPending\(\)#'
|
||||||
|
paths:
|
||||||
|
- src/Concerns/HasTenantOptions.php
|
||||||
-
|
-
|
||||||
message: '#invalid type Laravel\\Telescope\\IncomingEntry#'
|
message: '#invalid type Laravel\\Telescope\\IncomingEntry#'
|
||||||
paths:
|
paths:
|
||||||
|
|
@ -53,6 +59,4 @@ parameters:
|
||||||
paths:
|
paths:
|
||||||
- src/RLS/PolicyManagers/TraitRLSManager.php
|
- src/RLS/PolicyManagers/TraitRLSManager.php
|
||||||
|
|
||||||
checkMissingIterableValueType: false
|
|
||||||
checkGenericClassInNonGenericObjectType: false # later we may want to enable this
|
|
||||||
treatPhpDocTypesAsCertain: false
|
treatPhpDocTypesAsCertain: false
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,9 @@ class CloneRoutesAsTenant
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Route>
|
||||||
|
*/
|
||||||
protected function getRoutesToClone(): Collection
|
protected function getRoutesToClone(): Collection
|
||||||
{
|
{
|
||||||
$tenantParameterName = PathTenantResolver::tenantParameterName();
|
$tenantParameterName = PathTenantResolver::tenantParameterName();
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ class CreateStorageSymlinksAction
|
||||||
{
|
{
|
||||||
use DealsWithTenantSymlinks;
|
use DealsWithTenantSymlinks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Tenant|Collection<covariant int|string, Tenant&\Illuminate\Database\Eloquent\Model>|LazyCollection<covariant int|string, Tenant&\Illuminate\Database\Eloquent\Model> $tenants
|
||||||
|
*/
|
||||||
public function __invoke(Tenant|Collection|LazyCollection $tenants, bool $relativeLink = false, bool $force = false): void
|
public function __invoke(Tenant|Collection|LazyCollection $tenants, bool $relativeLink = false, bool $force = false): void
|
||||||
{
|
{
|
||||||
$tenants = $tenants instanceof Tenant ? collect([$tenants]) : $tenants;
|
$tenants = $tenants instanceof Tenant ? collect([$tenants]) : $tenants;
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@ class RemoveStorageSymlinksAction
|
||||||
{
|
{
|
||||||
use DealsWithTenantSymlinks;
|
use DealsWithTenantSymlinks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Tenant|Collection<covariant int|string, Tenant&\Illuminate\Database\Eloquent\Model>|LazyCollection<covariant int|string, Tenant&\Illuminate\Database\Eloquent\Model> $tenants
|
||||||
|
*/
|
||||||
public function __invoke(Tenant|Collection|LazyCollection $tenants): void
|
public function __invoke(Tenant|Collection|LazyCollection $tenants): void
|
||||||
{
|
{
|
||||||
$tenants = $tenants instanceof Tenant ? collect([$tenants]) : $tenants;
|
$tenants = $tenants instanceof Tenant ? collect([$tenants]) : $tenants;
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,9 @@ class Link extends Command
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param LazyCollection<covariant int|string, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model> $tenants
|
||||||
|
*/
|
||||||
protected function removeLinks(LazyCollection $tenants): void
|
protected function removeLinks(LazyCollection $tenants): void
|
||||||
{
|
{
|
||||||
(new RemoveStorageSymlinksAction)($tenants);
|
(new RemoveStorageSymlinksAction)($tenants);
|
||||||
|
|
@ -49,6 +52,9 @@ class Link extends Command
|
||||||
$this->components->info('The links have been removed.');
|
$this->components->info('The links have been removed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param LazyCollection<covariant int|string, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model> $tenants
|
||||||
|
*/
|
||||||
protected function createLinks(LazyCollection $tenants): void
|
protected function createLinks(LazyCollection $tenants): void
|
||||||
{
|
{
|
||||||
(new CreateStorageSymlinksAction)(
|
(new CreateStorageSymlinksAction)(
|
||||||
|
|
|
||||||
|
|
@ -52,20 +52,23 @@ class Migrate extends MigrateCommand
|
||||||
|
|
||||||
if ($this->getProcesses() > 1) {
|
if ($this->getProcesses() > 1) {
|
||||||
return $this->runConcurrently($this->getTenantChunks()->map(function ($chunk) {
|
return $this->runConcurrently($this->getTenantChunks()->map(function ($chunk) {
|
||||||
return $this->getTenants(array_values($chunk->all()));
|
return $this->getTenants($chunk->all());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->migrateTenants($this->getTenants()) ? 0 : 1;
|
return $this->migrateTenants($this->getTenants()) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function childHandle(...$args): bool
|
protected function childHandle(mixed ...$args): bool
|
||||||
{
|
{
|
||||||
$chunk = $args[0];
|
$chunk = $args[0];
|
||||||
|
|
||||||
return $this->migrateTenants($chunk);
|
return $this->migrateTenants($chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param LazyCollection<covariant int|string, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model> $tenants
|
||||||
|
*/
|
||||||
protected function migrateTenants(LazyCollection $tenants): bool
|
protected function migrateTenants(LazyCollection $tenants): bool
|
||||||
{
|
{
|
||||||
$success = true;
|
$success = true;
|
||||||
|
|
|
||||||
|
|
@ -38,14 +38,18 @@ class MigrateFresh extends BaseCommand
|
||||||
|
|
||||||
if ($this->getProcesses() > 1) {
|
if ($this->getProcesses() > 1) {
|
||||||
return $this->runConcurrently($this->getTenantChunks()->map(function ($chunk) {
|
return $this->runConcurrently($this->getTenantChunks()->map(function ($chunk) {
|
||||||
return $this->getTenants(array_values($chunk->all()));
|
return $this->getTenants($chunk->all());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
tenancy()->runForMultiple($this->getTenants(), function ($tenant) use (&$success) {
|
tenancy()->runForMultiple($this->getTenants(), function ($tenant) use (&$success) {
|
||||||
$this->components->info("Tenant: {$tenant->getTenantKey()}");
|
$this->components->info("Tenant: {$tenant->getTenantKey()}");
|
||||||
$this->components->task('Dropping tables', fn () => $success = $success && $this->wipeDB());
|
$this->components->task('Dropping tables', function () use (&$success) {
|
||||||
$this->components->task('Migrating', fn () => $success = $success && $this->migrateTenant($tenant));
|
$success = $success && $this->wipeDB();
|
||||||
|
});
|
||||||
|
$this->components->task('Migrating', function () use ($tenant, &$success) {
|
||||||
|
$success = $success && $this->migrateTenant($tenant);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return $success ? 0 : 1;
|
return $success ? 0 : 1;
|
||||||
|
|
@ -69,13 +73,16 @@ class MigrateFresh extends BaseCommand
|
||||||
]) === 0;
|
]) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function childHandle(...$args): bool
|
protected function childHandle(mixed ...$args): bool
|
||||||
{
|
{
|
||||||
$chunk = $args[0];
|
$chunk = $args[0];
|
||||||
|
|
||||||
return $this->migrateFreshTenants($chunk);
|
return $this->migrateFreshTenants($chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param LazyCollection<covariant int|string, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model> $tenants
|
||||||
|
*/
|
||||||
protected function migrateFreshTenants(LazyCollection $tenants): bool
|
protected function migrateFreshTenants(LazyCollection $tenants): bool
|
||||||
{
|
{
|
||||||
$success = true;
|
$success = true;
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class Rollback extends RollbackCommand
|
||||||
|
|
||||||
if ($this->getProcesses() > 1) {
|
if ($this->getProcesses() > 1) {
|
||||||
return $this->runConcurrently($this->getTenantChunks()->map(function ($chunk) {
|
return $this->runConcurrently($this->getTenantChunks()->map(function ($chunk) {
|
||||||
return $this->getTenants(array_values($chunk->all()));
|
return $this->getTenants($chunk->all());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,13 +54,16 @@ class Rollback extends RollbackCommand
|
||||||
return 'tenants:rollback';
|
return 'tenants:rollback';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function childHandle(...$args): bool
|
protected function childHandle(mixed ...$args): bool
|
||||||
{
|
{
|
||||||
$chunk = $args[0];
|
$chunk = $args[0];
|
||||||
|
|
||||||
return $this->rollbackTenants($chunk);
|
return $this->rollbackTenants($chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param LazyCollection<covariant int|string, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model> $tenants
|
||||||
|
*/
|
||||||
protected function rollbackTenants(LazyCollection $tenants): bool
|
protected function rollbackTenants(LazyCollection $tenants): bool
|
||||||
{
|
{
|
||||||
$success = true;
|
$success = true;
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,9 @@ class TenantList extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Generate the visual CLI output for the domain names. */
|
/** Generate the visual CLI output for the domain names. */
|
||||||
|
/**
|
||||||
|
* @param Collection<int|string, string>|null $domains
|
||||||
|
*/
|
||||||
protected function domainsCLI(?Collection $domains): ?string
|
protected function domainsCLI(?Collection $domains): ?string
|
||||||
{
|
{
|
||||||
if (! $domains) {
|
if (! $domains) {
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,17 @@ trait HasTenantOptions
|
||||||
], parent::getOptions());
|
], parent::getOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return LazyCollection<int, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model>
|
||||||
|
*/
|
||||||
protected function getTenants(?array $tenantKeys = null): LazyCollection
|
protected function getTenants(?array $tenantKeys = null): LazyCollection
|
||||||
{
|
{
|
||||||
return $this->getTenantsQuery($tenantKeys)->cursor();
|
return $this->getTenantsQuery($tenantKeys)->cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Builder<\Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model>
|
||||||
|
*/
|
||||||
protected function getTenantsQuery(?array $tenantKeys = null): Builder
|
protected function getTenantsQuery(?array $tenantKeys = null): Builder
|
||||||
{
|
{
|
||||||
return tenancy()->query()
|
return tenancy()->query()
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@ trait ParallelCommand
|
||||||
{
|
{
|
||||||
public const MAX_PROCESSES = 24;
|
public const MAX_PROCESSES = 24;
|
||||||
|
|
||||||
abstract protected function childHandle(...$args): bool;
|
abstract protected function childHandle(mixed ...$args): bool;
|
||||||
|
|
||||||
public function addProcessesOption(): void
|
public function addProcessesOption(): void
|
||||||
{
|
{
|
||||||
$this->addOption('processes', 'p', InputOption::VALUE_OPTIONAL, 'How many processes to spawn. Maximum value: ' . static::MAX_PROCESSES . ', recommended value: core count', 1);
|
$this->addOption('processes', 'p', InputOption::VALUE_OPTIONAL, 'How many processes to spawn. Maximum value: ' . static::MAX_PROCESSES . ', recommended value: core count', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function forkProcess(...$args): int
|
protected function forkProcess(mixed ...$args): int
|
||||||
{
|
{
|
||||||
$pid = pcntl_fork();
|
$pid = pcntl_fork();
|
||||||
|
|
||||||
|
|
@ -53,14 +53,25 @@ trait ParallelCommand
|
||||||
return $processes;
|
return $processes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Collection<int, Collection<int, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model>>>
|
||||||
|
*/
|
||||||
protected function getTenantChunks(): Collection
|
protected function getTenantChunks(): Collection
|
||||||
{
|
{
|
||||||
$idCol = tenancy()->model()->getTenantKeyName();
|
$idCol = tenancy()->model()->getTenantKeyName();
|
||||||
$tenants = tenancy()->model()->orderBy($idCol, 'asc')->pluck($idCol);
|
$tenants = tenancy()->model()->orderBy($idCol, 'asc')->pluck($idCol);
|
||||||
|
|
||||||
return $tenants->chunk(ceil($tenants->count() / $this->getProcesses()));
|
return $tenants->chunk((int) ceil($tenants->count() / $this->getProcesses()))->map(function ($chunk) {
|
||||||
|
$chunk = array_values($chunk->all());
|
||||||
|
|
||||||
|
/** @var Collection<int, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model> $chunk */
|
||||||
|
return $chunk;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array|ArrayAccess<int, mixed>|null $args
|
||||||
|
*/
|
||||||
protected function runConcurrently(array|ArrayAccess|null $args = null): int
|
protected function runConcurrently(array|ArrayAccess|null $args = null): int
|
||||||
{
|
{
|
||||||
$processes = $this->getProcesses();
|
$processes = $this->getProcesses();
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,19 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\Contracts;
|
namespace Stancl\Tenancy\Contracts;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use \Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property-read Tenant $tenant
|
* @property-read Tenant $tenant
|
||||||
*
|
*
|
||||||
* @see \Stancl\Tenancy\Database\Models\Domain
|
* @see \Stancl\Tenancy\Database\Models\Domain
|
||||||
*
|
*
|
||||||
* @mixin \Illuminate\Database\Eloquent\Model
|
* @mixin Model
|
||||||
*/
|
*/
|
||||||
interface Domain
|
interface Domain
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @return BelongsTo<Tenant&Model, Model>
|
||||||
|
*/
|
||||||
public function tenant(): BelongsTo;
|
public function tenant(): BelongsTo;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ class PendingScope implements Scope
|
||||||
/**
|
/**
|
||||||
* Apply the scope to a given Eloquent query builder.
|
* Apply the scope to a given Eloquent query builder.
|
||||||
*
|
*
|
||||||
|
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function apply(Builder $builder, Model $model)
|
public function apply(Builder $builder, Model $model)
|
||||||
|
|
@ -32,6 +34,8 @@ class PendingScope implements Scope
|
||||||
/**
|
/**
|
||||||
* Extend the query builder with the needed functions.
|
* Extend the query builder with the needed functions.
|
||||||
*
|
*
|
||||||
|
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function extend(Builder $builder)
|
public function extend(Builder $builder)
|
||||||
|
|
@ -43,6 +47,8 @@ class PendingScope implements Scope
|
||||||
/**
|
/**
|
||||||
* Add the with-pending extension to the builder.
|
* Add the with-pending extension to the builder.
|
||||||
*
|
*
|
||||||
|
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function addWithPending(Builder $builder)
|
protected function addWithPending(Builder $builder)
|
||||||
|
|
@ -59,6 +65,8 @@ class PendingScope implements Scope
|
||||||
/**
|
/**
|
||||||
* Add the without-pending extension to the builder.
|
* Add the without-pending extension to the builder.
|
||||||
*
|
*
|
||||||
|
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function addWithoutPending(Builder $builder)
|
protected function addWithoutPending(Builder $builder)
|
||||||
|
|
@ -75,6 +83,8 @@ class PendingScope implements Scope
|
||||||
/**
|
/**
|
||||||
* Add the only-pending extension to the builder.
|
* Add the only-pending extension to the builder.
|
||||||
*
|
*
|
||||||
|
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function addOnlyPending(Builder $builder)
|
protected function addOnlyPending(Builder $builder)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,9 @@ use Illuminate\Database\Eloquent\Scope;
|
||||||
|
|
||||||
class ParentModelScope implements Scope
|
class ParentModelScope implements Scope
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param Builder<Model> $builder
|
||||||
|
*/
|
||||||
public function apply(Builder $builder, Model $model): void
|
public function apply(Builder $builder, Model $model): void
|
||||||
{
|
{
|
||||||
if (! tenancy()->initialized) {
|
if (! tenancy()->initialized) {
|
||||||
|
|
@ -19,6 +22,9 @@ class ParentModelScope implements Scope
|
||||||
$builder->whereHas($builder->getModel()->getRelationshipToPrimaryModel());
|
$builder->whereHas($builder->getModel()->getRelationshipToPrimaryModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Builder<Model> $builder
|
||||||
|
*/
|
||||||
public function extend(Builder $builder): void
|
public function extend(Builder $builder): void
|
||||||
{
|
{
|
||||||
$builder->macro('withoutParentModel', function (Builder $builder) {
|
$builder->macro('withoutParentModel', function (Builder $builder) {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ use Stancl\Tenancy\Contracts\Tenant;
|
||||||
* @method Tenant[] toArray()
|
* @method Tenant[] toArray()
|
||||||
* @method Tenant offsetGet($key)
|
* @method Tenant offsetGet($key)
|
||||||
* @method Tenant first()
|
* @method Tenant first()
|
||||||
|
*
|
||||||
|
* @extends Collection<int|string, Tenant&\Illuminate\Database\Eloquent\Model>
|
||||||
*/
|
*/
|
||||||
class TenantCollection extends Collection
|
class TenantCollection extends Collection
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@ use Stancl\Tenancy\Tenancy;
|
||||||
|
|
||||||
class TenantScope implements Scope
|
class TenantScope implements Scope
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param Builder<Model> $builder
|
||||||
|
*/
|
||||||
public function apply(Builder $builder, Model $model)
|
public function apply(Builder $builder, Model $model)
|
||||||
{
|
{
|
||||||
if (! tenancy()->initialized) {
|
if (! tenancy()->initialized) {
|
||||||
|
|
@ -20,6 +23,9 @@ class TenantScope implements Scope
|
||||||
$builder->where($model->qualifyColumn(Tenancy::tenantKeyColumn()), tenant()->getTenantKey());
|
$builder->where($model->qualifyColumn(Tenancy::tenantKeyColumn()), tenant()->getTenantKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Builder<Model> $builder
|
||||||
|
*/
|
||||||
public function extend(Builder $builder): void
|
public function extend(Builder $builder): void
|
||||||
{
|
{
|
||||||
$builder->macro('withoutTenancy', function (Builder $builder) {
|
$builder->macro('withoutTenancy', function (Builder $builder) {
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ class InitializeTenancyByRequestData extends IdentificationMiddleware
|
||||||
} elseif (static::$cookie && $request->hasCookie(static::$cookie)) {
|
} elseif (static::$cookie && $request->hasCookie(static::$cookie)) {
|
||||||
$payload = $request->cookie(static::$cookie);
|
$payload = $request->cookie(static::$cookie);
|
||||||
|
|
||||||
if ($payload) {
|
if ($payload && is_string($payload)) {
|
||||||
$payload = $this->getTenantFromCookie($payload);
|
$payload = $this->getTenantFromCookie($payload);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,9 @@ class TraitRLSManager implements RLSPolicyManager
|
||||||
SQL;
|
SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param BelongsTo<Model, Model> $parentRelationship
|
||||||
|
*/
|
||||||
protected function generateIndirectRLSPolicyQuery(Model $model, BelongsTo $parentRelationship): string
|
protected function generateIndirectRLSPolicyQuery(Model $model, BelongsTo $parentRelationship): string
|
||||||
{
|
{
|
||||||
$table = $model->getTable();
|
$table = $model->getTable();
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ use Stancl\Tenancy\Contracts\Tenant;
|
||||||
*/
|
*/
|
||||||
interface SyncMaster extends Syncable
|
interface SyncMaster extends Syncable
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @return BelongsToMany<Tenant&Model>
|
||||||
|
*/
|
||||||
public function tenants(): BelongsToMany;
|
public function tenants(): BelongsToMany;
|
||||||
|
|
||||||
public function getTenantModelName(): string;
|
public function getTenantModelName(): string;
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,9 @@ class Tenancy
|
||||||
return in_array($bootstrapper, static::getBootstrappers(), true);
|
return in_array($bootstrapper, static::getBootstrappers(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Builder<Tenant&Model>
|
||||||
|
*/
|
||||||
public static function query(): Builder
|
public static function query(): Builder
|
||||||
{
|
{
|
||||||
return static::model()->query();
|
return static::model()->query();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue