49 lines
1022 B
PHP
49 lines
1022 B
PHP
<?php
|
|
|
|
namespace App\Domains\Cart\Models;
|
|
|
|
use App\Domains\Catalog\Models\ProductVariant;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
#[Fillable([
|
|
'cart_id',
|
|
'buyable_id',
|
|
'buyable_type',
|
|
'cantidad',
|
|
])]
|
|
class CartItem extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'carrito_items';
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'cart_id' => 'integer',
|
|
'buyable_id' => 'integer',
|
|
'buyable_type' => 'string',
|
|
'cantidad' => 'integer',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Cart, $this>
|
|
*/
|
|
public function cart(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Cart::class, 'cart_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
*/
|
|
public function buyable()
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
}
|