getAttribute($this->getTenantKeyName()); } public function newCollection(array $models = []): TenantCollection { return new TenantCollection($models); } public function getCasts() { return array_merge($this->dataColumnCasts(), [ 'id' => $this->getIncrementing() ? 'integer' : 'string', ]); } public static function internalPrefix(): string { return config('tenancy.internal_prefix'); } /** * Get an internal key. */ public function getInternal(string $key) { return $this->getAttribute(static::internalPrefix() . $key); } /** * Set internal key. */ public function setInternal(string $key, $value) { $this->setAttribute(static::internalPrefix() . $key, $value); return $this; } public function run(callable $callback) { $originalTenant = tenant(); tenancy()->initialize($this); $result = $callback($this); if ($originalTenant) { tenancy()->initialize($originalTenant); } else { tenancy()->end(); } return $result; } public $dispatchesEvents = [ 'saved' => Events\TenantSaved::class, 'created' => Events\TenantCreated::class, 'updated' => Events\TenantUpdated::class, 'deleted' => Events\TenantDeleted::class, ]; }