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

Add/update comments

This commit is contained in:
lukinovec 2023-06-19 12:57:16 +02:00
parent 1fd1aa7ad6
commit 8d13ce7e2f
3 changed files with 15 additions and 1 deletions

View file

@ -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
*/

View file

@ -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.
*/

View file

@ -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));