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
| Attribute | Type | Description |
|---|---|---|
id | int | Primary key |
product_id | int | Foreign key to Product |
product_specification_id | int | Foreign key to ProductSpecification |
value | string | Specification value |
metadata | json | Additional JSON data |
created_at | timestamp | Creation timestamp |
updated_at | timestamp | Last update timestamp |
Relationships
Belongs To
belongsTo(Product)- Associated productbelongsTo(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();Related Models
- Product - Associated product
- ProductSpecification - Specification template