1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 12:44:02 +00:00

Model timestamps

This commit is contained in:
Samuel Štancl 2019-09-27 22:53:38 +02:00
parent 4b5554dcac
commit 6b103cd2cb
6 changed files with 10 additions and 6 deletions

View file

@ -17,9 +17,11 @@ class CreateTenantsTable extends Migration
{
Schema::create('tenants', function (Blueprint $table) {
$table->string('id', 36)->primary(); // 36 characters is the default uuid length
// (optional) your custom, indexed columns can go here
// (optional) your custom, indexed columns may go here
$table->json('data');
$table->timestamps();
});
}

View file

@ -18,6 +18,7 @@ class CreateDomainsTable extends Migration
Schema::create('domains', function (Blueprint $table) {
$table->string('domain', 255)->primary();
$table->string('tenant_id', 36);
$table->timestamps();
$table->foreign('tenant_id')->references('id')->on('tenants')->onUpdate('cascade')->onDelete('cascade');
});

View file

@ -12,7 +12,8 @@
"require": {
"illuminate/support": "^6.0",
"webpatser/laravel-uuid": "^3.0",
"facade/ignition-contracts": "^1.0"
"facade/ignition-contracts": "^1.0",
"nesbot/carbon": "^2.0"
},
"require-dev": {
"vlucas/phpdotenv": "^3.3",

View file

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Stancl\Tenancy\StorageDrivers\Database;
use Illuminate\Foundation\Application;
use Illuminate\Support\Carbon;
use Stancl\Tenancy\Contracts\StorageDriver;
use Stancl\Tenancy\DatabaseManager;
use Stancl\Tenancy\Exceptions\DomainsOccupiedByOtherTenantException;
@ -84,9 +85,10 @@ class DatabaseStorageDriver implements StorageDriver
$domainData = [];
foreach ($tenant->domains as $domain) {
$domainData[] = ['domain' => $domain, 'tenant_id' => $tenant->id];
$domainData[] = ['domain' => $domain, 'tenant_id' => $tenant->id, 'created_at' => Carbon::now()];
}
Domains::create($domainData);
Domains::insert($domainData);
});
}

View file

@ -16,7 +16,6 @@ class DomainModel extends Model
protected $guarded = [];
protected $primaryKey = 'domain';
public $incrementing = false;
public $timestamps = false;
public function getTable()
{

View file

@ -16,7 +16,6 @@ class TenantModel extends Model
protected $guarded = [];
protected $primaryKey = 'id';
public $incrementing = false;
public $timestamps = false;
public function getTable()
{