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:
parent
1fd1aa7ad6
commit
8d13ce7e2f
3 changed files with 15 additions and 1 deletions
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue