From 8d13ce7e2f21c28bbad21377974afa0ae4297cd7 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 19 Jun 2023 12:57:16 +0200 Subject: [PATCH] Add/update comments --- assets/config.php | 5 +++++ src/Commands/CreateRLSPoliciesForTenantTables.php | 5 ++++- src/Database/Concerns/DealsWithModels.php | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/assets/config.php b/assets/config.php index d810235a..fbe3b8be 100644 --- a/assets/config.php +++ b/assets/config.php @@ -197,6 +197,11 @@ return [ /** * Directories in which Tenancy will discover your models. + * Subdirectories of the specified directories are also scanned. + * + * For example, specifying 'app/Models' will discover all models in the 'app/Models' directory and all of its subdirectories. + * Specifying 'app/Models/*' will discover all models in the subdirectories of 'app/Models' (+ their subdirectories), + * but not the models present directly in the 'app/Models' directory. * * @see Stancl\Tenancy\Commands\CreateRLSPoliciesForTenantTables */ diff --git a/src/Commands/CreateRLSPoliciesForTenantTables.php b/src/Commands/CreateRLSPoliciesForTenantTables.php index af41c351..706735be 100644 --- a/src/Commands/CreateRLSPoliciesForTenantTables.php +++ b/src/Commands/CreateRLSPoliciesForTenantTables.php @@ -9,7 +9,10 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\DB; /** - * Creates and uses RLS policies for tables related to a tenant directly, or through a parent primary model's table. + * Creates and uses RLS policies for tables of models related to a tenant directly (using BelongsToTenant), + * or through a parent primary model (using BelongsToPrimaryModel). + * + * The models are discovered in the directories configured in the Tenancy config ('tenancy.rls.model_directories'). * * This command is used with Postgres + single-database tenancy. */ diff --git a/src/Database/Concerns/DealsWithModels.php b/src/Database/Concerns/DealsWithModels.php index f02f739a..23b8e802 100644 --- a/src/Database/Concerns/DealsWithModels.php +++ b/src/Database/Concerns/DealsWithModels.php @@ -14,6 +14,9 @@ trait DealsWithModels { public static Closure|null $modelDiscoveryOverride = null; + /** + * Discover all models in the directories configured in 'tenancy.rls.model_directories'. + */ public static function getModels(): Collection { if (static::$modelDiscoveryOverride) { @@ -40,6 +43,9 @@ trait DealsWithModels return $classes->filter(fn ($class) => $class instanceof Model); } + /** + * Filter all models retrieved by static::getModels() to get only the models that belong to tenants. + */ public static function getTenantModels(): Collection { return static::getModels()->filter(fn (Model $model) => tenancy()->modelBelongsToTenant($model) || tenancy()->modelBelongsToTenantIndirectly($model));