Basic tenant structure
This commit is contained in:
10
app/Scopes/CommonModel.php
Normal file
10
app/Scopes/CommonModel.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Scopes;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
abstract class CommonModel extends Model
|
||||
{
|
||||
|
||||
}
|
||||
13
app/Scopes/InstancedModel.php
Normal file
13
app/Scopes/InstancedModel.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Scopes;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
abstract class InstancedModel extends Model
|
||||
{
|
||||
protected static function booted()
|
||||
{
|
||||
static::addGlobalScope(new SiteScope());
|
||||
}
|
||||
}
|
||||
14
app/Scopes/SiteScope.php
Normal file
14
app/Scopes/SiteScope.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace App\Scopes;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
|
||||
class SiteScope implements Scope
|
||||
{
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
$builder->where($model->getTable() . '.tenant', app('tenant')->slug);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user