I am building an API. I have 2 tables Products and Product to category mapping. Products have multiple category.i'm not using Model.
DB::table('products_to_categories')
->LeftJoin('products', 'products.products_id', '=', 'products_to_categories.products_id')
->LeftJoin('categories_description','categories_description.categories_id','=','products_to_categories.categories_id')
->leftJoin('manufacturers','manufacturers.manufacturers_id','=','products.manufacturers_id')
->leftJoin('manufacturers_info','manufacturers.manufacturers_id','=','manufacturers_info.manufacturers_id')
Currently i'm getting the output
{
"products_id": 12,
"categories_id": 1,
"categories_description_id": 1,
"categories_name": "Animal Figures",
},
{
"products_id": 12,
"categories_id": 2,
"categories_description_id": 4,
"categories_name": "Arts Crafts",
}
I want to combine both and get an output of
{
"products_id": 12,
"categories_id": [1,2],
"categories_description_id": [1,4],
"categories_name": ["Animal Figures","Arts Crafts"]
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire