<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PurchaseOrderItem extends Model
{
use HasFactory;
protected $fillable = [
'id',
'order_id',
'order_item_id',
'product_id',
'attribute_id',
'attribute_option_id',
'created_at',
'updated_at',
];
protected $appends = [
'quantity'
];
public function product()
{
return $this->belongsTo(Product::class, 'product_id');
}
public function attribute()
{
return $this->belongsTo(Attribute::class, 'attribute_id');
}
public function attributeOption()
{
return $this->belongsTo(AttributeOption::class, 'attribute_option_id');
}
public function orderItem()
{
return $this->belongsTo(OrderItems::class, 'order_item_id');
}
public function order()
{
return $this->belongsTo(Order::class, 'order_id');
}
protected function getQuantityAttribute()
{
return $this->orderItem->quantity;
}
}