Files
compras/app/Models/BudgetReinforcement.php

36 lines
1.0 KiB
PHP

<?php
namespace App\Models;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
/** @property int $id
* @property int $tenant_id
* @property int $budget_id
* @property int $created_by
* @property int $amount_minor
* @property string $status
* @property string $payload_hash
*/
class BudgetReinforcement extends Model
{
use BelongsToTenant;
protected $guarded = ['id'];
protected $attributes = ['status' => 'pending'];
protected $hidden = ['payload_hash'];
protected static function booted(): void
{
static::updating(function (BudgetReinforcement $reinforcement) {
if ($reinforcement->getRawOriginal('status') !== 'pending' || array_diff(array_keys($reinforcement->getDirty()), ['status', 'reviewed_by', 'review_reason', 'reviewed_at', 'updated_at']) !== []) {
throw new \LogicException('Preservar o reforço e a decisão.');
}
});
static::deleting(fn () => throw new \LogicException('Não eliminar reforços orçamentais.'));
}
}