mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 19:14:03 +00:00
Domain model & resolver test
This commit is contained in:
parent
08ed5084d5
commit
e1a4054743
11 changed files with 158 additions and 8 deletions
|
|
@ -3,19 +3,42 @@
|
|||
namespace Stancl\Tenancy\Database\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Stancl\Tenancy\Events\DomainCreated;
|
||||
use Stancl\Tenancy\Events\DomainDeleted;
|
||||
use Stancl\Tenancy\Events\DomainSaved;
|
||||
use Stancl\Tenancy\Events\DomainUpdated;
|
||||
use Stancl\Tenancy\Exceptions\DomainsOccupiedByOtherTenantException;
|
||||
|
||||
/**
|
||||
* @property string $domain
|
||||
* @property string $tenant_id
|
||||
*
|
||||
* @property-read Tenant $tenant
|
||||
*/
|
||||
class Domain extends Model
|
||||
{
|
||||
public function tenant()
|
||||
public $guarded = [];
|
||||
|
||||
public static function booted()
|
||||
{
|
||||
return $this->belongsTo(Tenant::class);
|
||||
$ensureDomainIsNotOccupied = function (Domain $self) {
|
||||
if ($domain = Domain::where('domain', $self->domain)->first()) {
|
||||
if ($domain->getKey() !== $self->getKey()) {
|
||||
throw new DomainsOccupiedByOtherTenantException;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static::saving($ensureDomainIsNotOccupied);
|
||||
}
|
||||
|
||||
protected $dispatchEvents = [
|
||||
public function tenant()
|
||||
{
|
||||
return $this->belongsTo(config('tenancy.tenant_model'));
|
||||
}
|
||||
|
||||
public $dispatchEvents = [
|
||||
'saved' => DomainSaved::class,
|
||||
'created' => DomainCreated::class,
|
||||
'updated' => DomainUpdated::class,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue