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:
parent
b3d9090284
commit
bc28b0c2ed
2 changed files with 18 additions and 2 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
15
src/Database/Concerns/RLSModel.php
Normal file
15
src/Database/Concerns/RLSModel.php
Normal 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
|
||||
{
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue