mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 00:34:03 +00:00
Initial commit
This commit is contained in:
commit
deb3ad77f5
19 changed files with 1283 additions and 0 deletions
30
src/Tenant.php
Normal file
30
src/Tenant.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy;
|
||||
|
||||
class Tenant
|
||||
{
|
||||
public $uuid;
|
||||
public $domain;
|
||||
public $databaseName;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array|string $data
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$data = is_string($data) ? json_decode($data, true) : (array) $data;
|
||||
|
||||
$this->uuid = $data['uuid'];
|
||||
$this->domain = $data['domain'] ?? tenancy()->getTenantById($data['uuid'], 'domain');
|
||||
$this->databaseName = $data['database_name'] ?? $this->getDatabaseName($data);
|
||||
}
|
||||
|
||||
public function getDatabaseName($uuid = null)
|
||||
{
|
||||
$uuid = $uuid ?: $this->uuid;
|
||||
return config('tenancy.database._prefix_base') . $uuid . config('tenancy.database._suffix');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue