Files
compras/app/Models/Concerns/BelongsToTenant.php
T
nala 7486007fcf
tests / ci (push) Waiting to run
commit compras4 2711
2026-11-27 19:13:31 +02:00

20 lines
602 B
PHP

<?php
namespace App\Models\Concerns;
use App\Services\ReplenishmentRun;
use App\Services\RequisitionExpiryRun;
use Illuminate\Database\Eloquent\Builder;
trait BelongsToTenant
{
protected static function bootBelongsToTenant(): void
{
static::addGlobalScope('tenant', function (Builder $query) {
$tenantId = auth()->check() ? auth()->user()->tenant_id : (app(ReplenishmentRun::class)->tenantId()
?? app(RequisitionExpiryRun::class)->tenantId());
$query->where($query->getModel()->qualifyColumn('tenant_id'), $tenantId ?? 0);
});
}
}