我有三个表:
categories table fields id, category_name
subcategories table fields id, category_id, subcategory_name
child_categories table fields id, category_id, subcategory_id, child_category_name
我有三个模型类别,子类别,
1) =>类别型号代码
class Category extends model {
public function subcategory(){
return $this->hasMany(Subcategory::class);
}
public function Child_category(){
return $this->hasMany(Child_category::class);
}
}
2) =>子类别型号代码
class Subcategory extends model {
public function Category(){
return $this->belongsTo(Category::class);
}
}
3) =>Child_category 型号代码
class Child_category extends model {
public function Category(){
return $this->belongsTo(Category::class);
}
}
如何建立 Eloquent 关系以从 child_categories 表中查找具有相关类别和子类别名称的所有数据?