'how to laravel same id to show array

my api response

[
    {
        "id": 1,
        "details": "plan1",
        "created_at": "2022-02-02 05:56:49",
        "updated_at": "2022-02-02 05:56:49",
        "select_subcategory": [
            {
                "id": 1,
                "subcategor_name": "regular",
                "created_at": "2022-02-02 05:56:24",
                "updated_at": "2022-02-02 05:56:24",
                "pivot": {
                    "plan_detail_id": "1",
                    "plan_sucategory_id": "1"
                }
            }
        ]
    },
    {
        "id": 2,
        "details": "plan2",
        "created_at": "2022-02-02 05:57:01",
        "updated_at": "2022-02-02 05:57:01",
        "select_subcategory": [
            {
                "id": 1,
                "subcategor_name": "regular",
                "created_at": "2022-02-02 05:56:24",
                "updated_at": "2022-02-02 05:56:24",
                "pivot": {
                    "plan_detail_id": "2",
                    "plan_sucategory_id": "1"
                }
            }
        ]
    },
    {
        "id": 3,
        "details": "plan1",
        "created_at": "2022-02-02 05:57:11",
        "updated_at": "2022-02-02 05:57:11",
        "select_subcategory": [
            {
                "id": 2,
                "subcategor_name": "premium",
                "created_at": "2022-02-02 05:56:36",
                "updated_at": "2022-02-02 05:56:36",
                "pivot": {
                    "plan_detail_id": "3",
                    "plan_sucategory_id": "2"
                }
            }
        ]
    },
    {
        "id": 4,
        "details": "plan3",
        "created_at": "2022-02-02 05:57:21",
        "updated_at": "2022-02-02 05:57:21",
        "select_subcategory": [
            {
                "id": 2,
                "subcategor_name": "premium",
                "created_at": "2022-02-02 05:56:36",
                "updated_at": "2022-02-02 05:56:36",
                "pivot": {
                    "plan_detail_id": "4",
                    "plan_sucategory_id": "2"
                }
            }
        ]
    },
    {
        "id": 5,
        "details": "test",
        "created_at": "2022-02-02 08:47:33",
        "updated_at": "2022-02-02 08:47:33",
        "select_subcategory": [
            {
                "id": 1,
                "subcategor_name": "regular",
                "created_at": "2022-02-02 05:56:24",
                "updated_at": "2022-02-02 05:56:24",
                "pivot": {
                    "plan_detail_id": "5",
                    "plan_sucategory_id": "1"
                }
            }
        ]
    }
]

i want to show api response

[
    {
    
        "select_subcategory": [
            {
                "id": 1,
                "subcategor_name": "regular",
                "created_at": "2022-02-02 05:56:24",
                "updated_at": "2022-02-02 05:56:24",
                        "details": [
                        
                        "plan1","plan2"
                        ],

                "pivot": {
                    "plan_detail_id": "1",
                    "plan_sucategory_id": "1"
                }
            }
        ]
    }
    
    ]

laravel rest api i wnt to show plan_sucategory_id=1 show array inlaravel rest api i wnt to show plan_sucategory_id=1 show array inlaravel rest api i wnt to show plan_sucategory_id=1 show array inlaravel rest api i wnt to show plan_sucategory_id=1 show array inlaravel rest api i wnt to show plan_sucategory_id=1 show array in



Solution 1:[1]

$res = array_values($banners)
return response()->json($res);

simple please try this!

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Piyush S