mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 22:44:04 +00:00
This PR adds Postgres RLS (trait manager + table manager approach) and permission controlled managers for PostgreSQL. --------- Co-authored-by: lukinovec <lukinovec@gmail.com> Co-authored-by: PHP CS Fixer <phpcsfixer@example.com>
22 lines
606 B
PHP
22 lines
606 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Database\Concerns;
|
|
|
|
use Stancl\Tenancy\Tenancy;
|
|
|
|
trait FillsCurrentTenant
|
|
{
|
|
public static function bootFillsCurrentTenant(): void
|
|
{
|
|
static::creating(function ($model) {
|
|
if (! $model->getAttribute(Tenancy::tenantKeyColumn()) && ! $model->relationLoaded('tenant')) {
|
|
if (tenancy()->initialized) {
|
|
$model->setAttribute(Tenancy::tenantKeyColumn(), tenant()->getTenantKey());
|
|
$model->setRelation('tenant', tenant());
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|