up
This commit is contained in:
@@ -22,6 +22,8 @@ class Tela extends Model
|
||||
|
||||
protected $casts = [
|
||||
'foto' => 'string',
|
||||
'valor_total' => 'decimal:2',
|
||||
'costo_por_metro' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function proveedor()
|
||||
@@ -33,4 +35,24 @@ class Tela extends Model
|
||||
{
|
||||
return $this->hasMany(OrdenProduccion::class);
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::saving(function ($tela) {
|
||||
// Protección temporal: si la columna en la BD aún es integer, convertir a entero
|
||||
try {
|
||||
$type = \Illuminate\Support\Facades\Schema::getColumnType('telas', 'costo_por_metro');
|
||||
if ($type === 'integer') {
|
||||
$tela->costo_por_metro = (int) round($tela->costo_por_metro ?? 0);
|
||||
}
|
||||
|
||||
$typeVal = \Illuminate\Support\Facades\Schema::getColumnType('telas', 'valor_total');
|
||||
if ($typeVal === 'integer') {
|
||||
$tela->valor_total = (int) round($tela->valor_total ?? 0);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Ignorar si no se puede determinar el tipo de columna (por ejemplo en pruebas antes de migraciones)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user