This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
memberdb/app/ScopingTrait.php

32 lines
773 B
PHP
Raw Permalink Normal View History

<?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}''";
}
}