Skip to main content

OrderItem Model

The OrderItem model represents individual items within an order. It manages item details, associated products, and returns

Relationships

  • **Product:**Each order item is associated with a specific product
    public function product()
    {
    return $this->belongsTo(Product::class, 'shop_product_id');
    }


  • **Order:**Each order item belongs to a specific order.

    public function order()
    {
    return $this->belongsTo(Order::class, 'shop_order_id');
    }

  • **Returns:**An order item can have multiple return requests associated with it.
    public function returns()
    {
    return $this->hasMany(Returns::class, 'item_id');
    }


  • **Activity Logging:**The model logs activities using the Spatie Activity Log package.
    public function order()
    {
    return $this->belongsTo(Order::class, 'shop_order_id');
    }

Table Columns

  • id - The primary key of the order items table.

-table - The associated table (shop_order_items).

  • shop_product_id - Foreign key linking the order item to a product.

  • shop_order_id - Foreign key linking the order item to an order.

  • created_at - Timestamp for record creation.

  • updated_at - Timestamp for last record update