@@ -0,0 +1,16 @@
|
||||
<?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 : null;
|
||||
$query->where($query->getModel()->qualifyColumn('tenant_id'), $tenantId ?? 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use LogicException;
|
||||
|
||||
trait ImmutablePurchaseRecord
|
||||
{
|
||||
protected static function bootImmutablePurchaseRecord(): void
|
||||
{
|
||||
static::updating(fn () => throw new LogicException('O documento emitido não pode ser reescrito.'));
|
||||
static::deleting(fn () => throw new LogicException('O documento emitido deve ser preservado.'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user