mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-04 21:14:02 +00:00
Add config('tenancy.database.rls')
This commit is contained in:
parent
cb775a9fba
commit
bad5c693ab
2 changed files with 9 additions and 6 deletions
|
|
@ -10,10 +10,6 @@ return [
|
||||||
* Configuration for the models used by Tenancy.
|
* Configuration for the models used by Tenancy.
|
||||||
*/
|
*/
|
||||||
'models' => [
|
'models' => [
|
||||||
'rls' => [
|
|
||||||
// The tenants:create-rls-policies comand will create RLS policies
|
|
||||||
// For tables of the models specified here
|
|
||||||
],
|
|
||||||
'tenant' => Stancl\Tenancy\Database\Models\Tenant::class,
|
'tenant' => Stancl\Tenancy\Database\Models\Tenant::class,
|
||||||
'domain' => Stancl\Tenancy\Database\Models\Domain::class,
|
'domain' => Stancl\Tenancy\Database\Models\Domain::class,
|
||||||
|
|
||||||
|
|
@ -179,6 +175,13 @@ return [
|
||||||
|
|
||||||
// todo docblock
|
// todo docblock
|
||||||
'drop_tenant_databases_on_migrate_fresh' => false,
|
'drop_tenant_databases_on_migrate_fresh' => false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope tenant models using RLS.
|
||||||
|
*
|
||||||
|
* Requires Postgres with single-database tenancy.
|
||||||
|
*/
|
||||||
|
'rls' => false,
|
||||||
],
|
],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@ trait BelongsToTenant
|
||||||
|
|
||||||
public static function bootBelongsToTenant(): void
|
public static function bootBelongsToTenant(): void
|
||||||
{
|
{
|
||||||
// Queries of models present in the tenancy.models.rls config are scoped using Postgres RLS instead of the global scope
|
// If tenancy.database.rls is true, scope queries using Postgres RLS instead of TenantScope
|
||||||
if (! in_array(static::class, config('tenancy.models.rls'))) {
|
if (! config('tenancy.database.rls')) {
|
||||||
static::addGlobalScope(new TenantScope);
|
static::addGlobalScope(new TenantScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue