I have three tables:
I use one controller (CategoryController.php) and my three models are Attribute,AttributeValues and ProductAttribute
My controller:
$all_attributes = Attribute::with('attribute_values')->with('product_attribute')->get()->toArray();
My models are:
Attribute:
public function attribute_values(){
return $this->hasMany('AttributeValues');
}
public function product_attribute(){
return $this->hasMany('ProductAttribute');
}
AttributeValues:
public function attribute(){
return $this->belongsTo('Attribute');
}
ProductAttribute:
public function product(){
return $this->belongsTo('Product');
}
Generate a pivot table
php artisan generate:pivot tableone tabletwo
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community