This commit is contained in:
Lizandro Guarnizo
2026-01-06 15:35:59 -05:00
commit a768146f65
602 changed files with 42505 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Compra extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'fecha',
'proveedor_id',
'total',
'estado',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'id' => 'integer',
'fecha' => 'datetime',
'proveedor_id' => 'integer',
'total' => 'decimal:2',
];
public function proveedor(): BelongsTo
{
return $this->belongsTo(Proveedor::class);
}
public function detalles()
{
return $this->hasMany(DetalleCompra::class);
}
/**
* Boot del modelo para eventos
*/
protected static function boot()
{
parent::boot();
// Al eliminar una compra, eliminar sus detalles
static::deleting(function ($compra) {
$compra->detalles()->delete();
});
}
}