I've a scenario for product and attributes relationship.
Models:
- Product (table: products)
- Attributes (table: attributes)
- Attribute Values (table: attribute_values, foreign key: attribute_id)
A product can have multiple attributes so this will be easy with many to many relation b/w product and attributes
Model: Attribute
<?php
class Attribute extends Model{
public function products()
{
return $this->belongsToMany(Product::class);
}
}
Model: Product
class Product extends Model{
public function attributes()
{
return $this->belongsToMany(Attribute::class);
}
}
but, when assigning an attribute to an item user can opt out one of the attribute value from attribute_values i.e., the values assigned to an attribute.
how can I manage this in eloquent way?
