mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:54:03 +00:00
Change default tenant model, write more tests, cleanup
This commit is contained in:
parent
c32f229dd5
commit
de53b81c0e
33 changed files with 210 additions and 90 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Stancl\Tenancy\Database\Concerns;
|
||||
|
||||
trait HasADataColumn
|
||||
trait HasDataColumn
|
||||
{
|
||||
public static $priorityListeners = [];
|
||||
|
||||
|
|
@ -13,9 +13,9 @@ trait HasADataColumn
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dataEncodingStatus = 'decoded'; // todo write tests for this
|
||||
public $dataEncodingStatus = 'decoded';
|
||||
|
||||
public static function bootHasADataColumn()
|
||||
public static function bootHasDataColumn()
|
||||
{
|
||||
$encode = function (self $model) {
|
||||
if ($model->dataEncodingStatus === 'encoded') {
|
||||
16
src/Database/Concerns/HasDatabase.php
Normal file
16
src/Database/Concerns/HasDatabase.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Database\Concerns;
|
||||
|
||||
use Stancl\Tenancy\Contracts\TenantWithDatabase;
|
||||
use Stancl\Tenancy\DatabaseConfig;
|
||||
|
||||
trait HasDatabase
|
||||
{
|
||||
public function database(): DatabaseConfig
|
||||
{
|
||||
/** @var TenantWithDatabase $this */
|
||||
|
||||
return new DatabaseConfig($this);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,6 @@ namespace Stancl\Tenancy\Database\Models;
|
|||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Stancl\Tenancy\DatabaseConfig;
|
||||
use Stancl\Tenancy\Events;
|
||||
use Stancl\Tenancy\Contracts;
|
||||
use Stancl\Tenancy\Database\Concerns;
|
||||
|
|
@ -15,14 +14,13 @@ use Stancl\Tenancy\Database\Concerns;
|
|||
* @property Carbon $updated_at
|
||||
* @property array $data
|
||||
*/
|
||||
class Tenant extends Model implements Contracts\TenantWithDatabase // todo base model that isn't TenantWithDatabase & domains
|
||||
class Tenant extends Model implements Contracts\Tenant
|
||||
{
|
||||
use Concerns\CentralConnection,
|
||||
Concerns\HasADataColumn,
|
||||
Concerns\HasDataColumn,
|
||||
Concerns\GeneratesIds,
|
||||
Concerns\HasADataColumn,
|
||||
Concerns\HasDomains {
|
||||
Concerns\HasADataColumn::getCasts as dataColumnCasts;
|
||||
Concerns\HasDataColumn {
|
||||
Concerns\HasDataColumn::getCasts as dataColumnCasts;
|
||||
}
|
||||
|
||||
protected $table = 'tenants';
|
||||
|
|
@ -69,11 +67,6 @@ class Tenant extends Model implements Contracts\TenantWithDatabase // todo base
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function database(): DatabaseConfig
|
||||
{
|
||||
return new DatabaseConfig($this);
|
||||
}
|
||||
|
||||
public function run(callable $callback)
|
||||
{
|
||||
$originalTenant = tenant();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue