I have three table Product, Model and Variant. Product has many Model. Model has many Variant. There is product_id in Model table. There are product_id and model_id in Variant table.
How can I use hasMany() in Model model class to fetch Products along with Model and Variant in Product controller?
does variant belongs to model, which means one model has many variant.
in this case, depends on the name of the functions
# in Product class
public function models()
{
return $this->hasMany('Model');
}
# in Model class
public function variants()
{
return $this->hasMany('Variant');
}
# to find the product's models and its models variants, like
Product::with('models','models.variants')->find(1)