'How to create an array for another table details using name in select using mysql

I have saved all product name in the product table. after that im saving the product multiple details in product_details table. now i need to create a json like this json given below.

product_table

id name
1 rice
2 milk

product_details_table

id brand_name company_id
1 IGLU AER432
2 IGLU AER432
select *, array(
            select * 
            from product_details ) as product_details
from product

i want to create a json like this format in laravel

[
    {
        "id": 1,
        "name": "rice",
        "product_details":[
                            {
                                "brand_name":"IGLU",
                                "company_id":"AER432"
                           },
                           {
                                "brand_name":"IGLU",
                                "company_id":"AER432"
                           },
                           {
                                "brand_name":"IGLU",
                                "company_id":"AER432"
                           }    
        ]
    },

    {
        "id": 2,
        "name": "milk",
        "product_details":[
                            {
                                "brand_name":"IGLU",
                                "company_id":"AER432"
                           },
                           {
                                "brand_name":"IGLU",
                                "company_id":"AER432"
                           },
                           {
                                "brand_name":"IGLU",
                                "company_id":"AER432"
                           }    
        ]
    },
    
   
]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source