From cea10b2f2dc1a3b1f635010ec0c330ec387b5807 Mon Sep 17 00:00:00 2001 From: The Zach Date: Fri, 30 Sep 2022 16:18:16 -0400 Subject: [PATCH] 854 - possible resolve deprecation issue --- src/Database/Concerns/BelongsToTenant.php | 6 +++--- src/Database/Concerns/HasScopedValidationRules.php | 6 ++++-- src/Database/TenantScope.php | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Database/Concerns/BelongsToTenant.php b/src/Database/Concerns/BelongsToTenant.php index 5410758d..b09b9264 100644 --- a/src/Database/Concerns/BelongsToTenant.php +++ b/src/Database/Concerns/BelongsToTenant.php @@ -16,7 +16,7 @@ trait BelongsToTenant public function tenant() { - return $this->belongsTo(config('tenancy.tenant_model'), BelongsToTenant::$tenantIdColumn); + return $this->belongsTo(config('tenancy.tenant_model'), self::$tenantIdColumn); } public static function bootBelongsToTenant() @@ -24,9 +24,9 @@ trait BelongsToTenant static::addGlobalScope(new TenantScope); static::creating(function ($model) { - if (! $model->getAttribute(BelongsToTenant::$tenantIdColumn) && ! $model->relationLoaded('tenant')) { + if (! $model->getAttribute(self::$tenantIdColumn) && ! $model->relationLoaded('tenant')) { if (tenancy()->initialized) { - $model->setAttribute(BelongsToTenant::$tenantIdColumn, tenant()->getTenantKey()); + $model->setAttribute(self::$tenantIdColumn, tenant()->getTenantKey()); $model->setRelation('tenant', tenant()); } } diff --git a/src/Database/Concerns/HasScopedValidationRules.php b/src/Database/Concerns/HasScopedValidationRules.php index ae5c7fc7..f4afd257 100644 --- a/src/Database/Concerns/HasScopedValidationRules.php +++ b/src/Database/Concerns/HasScopedValidationRules.php @@ -9,13 +9,15 @@ use Illuminate\Validation\Rules\Unique; trait HasScopedValidationRules { + use BelongsToTenant; + public function unique($table, $column = 'NULL') { - return (new Unique($table, $column))->where(BelongsToTenant::$tenantIdColumn, $this->getTenantKey()); + return (new Unique($table, $column))->where(self::$tenantIdColumn, $this->getTenantKey()); } public function exists($table, $column = 'NULL') { - return (new Exists($table, $column))->where(BelongsToTenant::$tenantIdColumn, $this->getTenantKey()); + return (new Exists($table, $column))->where(self::$tenantIdColumn, $this->getTenantKey()); } } diff --git a/src/Database/TenantScope.php b/src/Database/TenantScope.php index 8592f16c..42c27e64 100644 --- a/src/Database/TenantScope.php +++ b/src/Database/TenantScope.php @@ -11,13 +11,15 @@ use Stancl\Tenancy\Database\Concerns\BelongsToTenant; class TenantScope implements Scope { + use BelongsToTenant; + public function apply(Builder $builder, Model $model) { if (! tenancy()->initialized) { return; } - $builder->where($model->qualifyColumn(BelongsToTenant::$tenantIdColumn), tenant()->getTenantKey()); + $builder->where($model->qualifyColumn(self::$tenantIdColumn), tenant()->getTenantKey()); } public function extend(Builder $builder)