I make a category and subcategory with Many To Many relationship
and i want to display it with Json api to be like this
[
{
"id": "1",
"title": "Main Category",
"subCategories": [
"id": "1",
"title": "SubCategory",
]
{
]
category Model
public function subcategory()
{
return $this->belongsToMany('App\Subcategory', 'category_id');
}
Subcategory Model
public function category()
{
return $this->belongsToMany('App\Categories', 'categories_subcategories');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire