42 lines
1.1 KiB
PHP
42 lines
1.1 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 $supplier_evaluation_id
|
|
* @property int $created_by
|
|
* @property int $version
|
|
* @property string $status
|
|
* @property array<string,mixed> $payload
|
|
* @property list<int> $contributors
|
|
* @property array<string,mixed>|null $decision
|
|
*/
|
|
class SupplierResponse extends Model
|
|
{
|
|
use BelongsToTenant;
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $attributes = ['status' => 'draft', 'version' => 1];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['payload' => 'array', 'contributors' => 'array', 'decision' => 'array', 'reviewed_at' => 'datetime'];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::updating(function (self $record) {
|
|
if ($record->getRawOriginal('status') === 'decided') {
|
|
throw new \LogicException('A conclusão registada conserva-se no histórico.');
|
|
}
|
|
});
|
|
static::deleting(fn () => throw new \LogicException('Preservar o contraditório do fornecedor.'));
|
|
}
|
|
}
|