1
0
Fork 0
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:
lukinovec 2023-05-09 16:07:06 +02:00
parent 3c098dc78e
commit 17d779e130
6 changed files with 71 additions and 33 deletions

View file

@ -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')) {