mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-06 16:14:05 +00:00
Scope queries using Postgres RLS (WIP)
This commit is contained in:
parent
3c098dc78e
commit
17d779e130
6 changed files with 71 additions and 33 deletions
|
|
@ -21,7 +21,11 @@ trait BelongsToTenant
|
|||
|
||||
public static function bootBelongsToTenant(): void
|
||||
{
|
||||
static::addGlobalScope(new TenantScope);
|
||||
// The queries performed for models present in the tenancy.models.rls are scoped using Postgres RLS instead of the global scope
|
||||
if (! in_array(static::class, config('tenancy.models.rls'))) {
|
||||
static::addGlobalScope(new TenantScope);
|
||||
}
|
||||
|
||||
|
||||
static::creating(function ($model) {
|
||||
if (! $model->getAttribute(Tenancy::tenantKeyColumn()) && ! $model->relationLoaded('tenant')) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue