Skip to content

ProductSpecificationValue Model

Stores actual values for product specifications for each product.

Overview

The ProductSpecificationValue model links a product to a specific specification and stores the value for that specification. It enables flexible, dynamic product attributes and supports advanced product filtering and search.

Attributes

AttributeTypeDescription
idintPrimary key
product_idintForeign key to Product
product_specification_idintForeign key to ProductSpecification
valuestringSpecification value
metadatajsonAdditional JSON data
created_attimestampCreation timestamp
updated_attimestampLast update timestamp

Relationships

Belongs To

  • belongsTo(Product) - Associated product
  • belongsTo(ProductSpecification) - Associated specification

Key Features

Flexible Attribute Storage

  • Stores dynamic product attributes
  • Supports multiple specifications per product
  • Enables advanced product filtering

Metadata Support

  • Store additional data per value
  • Flexible JSON metadata

Search Integration

  • Indexed for fast filtering
  • Supports specification-based product search

Usage Examples

Creating a Specification Value

php
$value = ProductSpecificationValue::create([
    'product_id' => $product->id,
    'product_specification_id' => $specification->id,
    'value' => '200mg',
    'metadata' => [
        'unit' => 'mg',
        'display' => '200 milligrams'
    ]
]);

Getting Associated Data

php
// Get product
$product = $value->product;

// Get specification
$spec = $value->productSpecification;

Querying Values

php
// Get all values for a product
$values = ProductSpecificationValue::where('product_id', $product->id)->get();

// Get all values for a specification
$values = ProductSpecificationValue::where('product_specification_id', $specification->id)->get();