1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-04 19:24:02 +00:00

Add RLSModel interface, update BelongsToTenant

This commit is contained in:
lukinovec 2023-06-07 09:37:32 +02:00
parent b3d9090284
commit bc28b0c2ed
2 changed files with 18 additions and 2 deletions

View file

@ -21,8 +21,9 @@ trait BelongsToTenant
public static function bootBelongsToTenant(): void
{
// If tenancy.database.rls is true, scope queries using Postgres RLS instead of TenantScope
if (! config('tenancy.database.rls')) {
// If tenancy.database.rls is true or this model implements RLSModel
// Scope queries using Postgres RLS instead of TenantScope
if (! (config('tenancy.database.rls') || in_array(RLSModel::class, class_implements(static::class)))) {
static::addGlobalScope(new TenantScope);
}

View file

@ -0,0 +1,15 @@
<?php
namespace Stancl\Tenancy\Database\Concerns;
/**
* Interface indicating that the queries of the model it's used on
* get scoped using RLS instead of the global TenantScope.
*
* Used with Postgres RLS (single-database tenancy).
*
* @see \Stancl\Tenancy\Database\Concerns\BelongsToTenant
*/
interface RLSModel
{
}