57 lines
1.3 KiB
PHP
57 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Purchase\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([
|
|
'compra_id',
|
|
'buyable_id',
|
|
'buyable_type',
|
|
'cantidad',
|
|
'precio_unitario',
|
|
'discount_total',
|
|
'tax_total',
|
|
'total',
|
|
])]
|
|
class PurchaseItem extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'compra_items';
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'compra_id' => 'integer',
|
|
'buyable_id' => 'integer',
|
|
'buyable_type' => 'string',
|
|
'cantidad' => 'integer',
|
|
'precio_unitario' => 'decimal:2',
|
|
'discount_total' => 'decimal:2',
|
|
'tax_total' => 'decimal:2',
|
|
'total' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<Purchase, $this>
|
|
*/
|
|
public function purchase(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Purchase::class, 'compra_id');
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
|
|
*/
|
|
public function buyable()
|
|
{
|
|
return $this->morphTo();
|
|
}
|
|
}
|