mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-18 04:04:04 +00:00
Single DB tenancy
This commit is contained in:
parent
99d460f76e
commit
28019f4528
6 changed files with 335 additions and 3 deletions
27
src/Database/TenantScope.php
Normal file
27
src/Database/TenantScope.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Database;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
use Stancl\Tenancy\Database\Concerns\BelongsToTenant;
|
||||
|
||||
class TenantScope implements Scope
|
||||
{
|
||||
public function apply(Builder $builder, Model $model)
|
||||
{
|
||||
if (! tenancy()->initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
$builder->where(BelongsToTenant::$tenantIdColumn, tenant()->getTenantKey());
|
||||
}
|
||||
|
||||
public function extend(Builder $builder)
|
||||
{
|
||||
$builder->macro('withoutTenancy', function (Builder $builder) {
|
||||
return $builder->withoutGlobalScope($this);
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue