32 lines
773 B
PHP
32 lines
773 B
PHP
<?php namespace App;
|
|
|
|
use App;
|
|
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Acme\Scoping\TenantScope;
|
|
|
|
trait TenantScopedModelTrait
|
|
{
|
|
public static function bootTenantScopedModelTrait()
|
|
{
|
|
dd(__METHOD__);
|
|
$tenantScope = App::make('Acme\Scoping\TenantScope');
|
|
|
|
// Add Global scope that will handle all operations except create()
|
|
static::addGlobalScope($tenantScope);
|
|
}
|
|
|
|
public static function allTenants()
|
|
{
|
|
dd(__METHOD__);
|
|
return with(new static())->newQueryWithoutScope(new TenantScope());
|
|
}
|
|
|
|
public function getTenantWhereClause($tenantColumn, $tenantId)
|
|
{
|
|
dd(__METHOD__);
|
|
return "{$this->getTable()}.{$tenantColumn} = '{$tenantId}''";
|
|
}
|
|
|
|
}
|