feat: implement Bundle and BundleItem models, migrations, and polymorphic relationships for cart and purchase items

This commit is contained in:
2026-07-14 16:02:26 -03:00
parent 18c80b075b
commit 1d56d27350
8 changed files with 323 additions and 10 deletions

View File

@@ -10,7 +10,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
#[Fillable([
'cart_id',
'producto_variante_id',
'buyable_id',
'buyable_type',
'cantidad',
])]
class CartItem extends Model
@@ -23,7 +24,8 @@ class CartItem extends Model
{
return [
'cart_id' => 'integer',
'producto_variante_id' => 'integer',
'buyable_id' => 'integer',
'buyable_type' => 'string',
'cantidad' => 'integer',
];
}
@@ -37,10 +39,10 @@ class CartItem extends Model
}
/**
* @return BelongsTo<ProductVariant, $this>
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function variant(): BelongsTo
public function buyable()
{
return $this->belongsTo(ProductVariant::class, 'producto_variante_id');
return $this->morphTo();
}
}