17 lines
476 B
PHP
17 lines
476 B
PHP
<?php
|
|
|
|
namespace App\Models\Concerns;
|
|
|
|
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(\App\Services\ReplenishmentRun::class)->tenantId();
|
|
$query->where($query->getModel()->qualifyColumn('tenant_id'), $tenantId ?? 0);
|
|
});
|
|
}
|
|
}
|