1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 18:14:04 +00:00

854 - possible resolve deprecation issue

This commit is contained in:
The Zach 2022-09-30 16:18:16 -04:00
parent 84a3287799
commit cea10b2f2d
No known key found for this signature in database
GPG key ID: EF7A0CD3DAA4F56F
3 changed files with 10 additions and 6 deletions

View file

@ -16,7 +16,7 @@ trait BelongsToTenant
public function tenant() 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() public static function bootBelongsToTenant()
@ -24,9 +24,9 @@ trait BelongsToTenant
static::addGlobalScope(new TenantScope); static::addGlobalScope(new TenantScope);
static::creating(function ($model) { static::creating(function ($model) {
if (! $model->getAttribute(BelongsToTenant::$tenantIdColumn) && ! $model->relationLoaded('tenant')) { if (! $model->getAttribute(self::$tenantIdColumn) && ! $model->relationLoaded('tenant')) {
if (tenancy()->initialized) { if (tenancy()->initialized) {
$model->setAttribute(BelongsToTenant::$tenantIdColumn, tenant()->getTenantKey()); $model->setAttribute(self::$tenantIdColumn, tenant()->getTenantKey());
$model->setRelation('tenant', tenant()); $model->setRelation('tenant', tenant());
} }
} }

View file

@ -9,13 +9,15 @@ use Illuminate\Validation\Rules\Unique;
trait HasScopedValidationRules trait HasScopedValidationRules
{ {
use BelongsToTenant;
public function unique($table, $column = 'NULL') 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') 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());
} }
} }

View file

@ -11,13 +11,15 @@ use Stancl\Tenancy\Database\Concerns\BelongsToTenant;
class TenantScope implements Scope class TenantScope implements Scope
{ {
use BelongsToTenant;
public function apply(Builder $builder, Model $model) public function apply(Builder $builder, Model $model)
{ {
if (! tenancy()->initialized) { if (! tenancy()->initialized) {
return; return;
} }
$builder->where($model->qualifyColumn(BelongsToTenant::$tenantIdColumn), tenant()->getTenantKey()); $builder->where($model->qualifyColumn(self::$tenantIdColumn), tenant()->getTenantKey());
} }
public function extend(Builder $builder) public function extend(Builder $builder)