Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ncltours's avatar

How to change to value of particular key in multiple nested collections in laravel?

I have the following nested collections.

  "hotels": [
        {
            "code": 2810,
            "name": "Hesperia Bristol Playa",
            "categoryCode": "3LL",
            "categoryName": "3 KEYS",
            "destinationCode": "FUE",
            "destinationName": "Fuerteventura",
            "zoneCode": 10,
            "zoneName": "Corralejo",
            "latitude": "28.7434",
            "longitude": "-13.86949",
            "rooms": [
                {
                    "code": "APT.B1",
                    "name": "APARTMENT ONE BEDROOM",
                    "rates": [
                        {
                            "rateKey": "20210327|20210329|W|53|2810|APT.B1|CG-FIT|SC||1~2~1|6|N@06~~2408a~-342496754~N~~~NOR~3F4CB63474874A1160855852805400PAUK000005700000000012408a",
                            "rateClass": "NOR",
                            "rateType": "BOOKABLE",
                            "net": "138.64",
                            "allotment": 43,
                            "paymentType": "AT_WEB",
                            "packaging": false,
                            "boardCode": "SC",
                            "boardName": "SELF CATERING",
                            "cancellationPolicies": [
                                {
                                    "amount": "69.32",
                                    "from": "2021-03-21T23:59:00Z"
                                }
                            ],
                            "rooms": 1,
                            "adults": 2,
                            "children": 1,
                            "childrenAges": "6"
                        }
                    ]
                },

I want to change the value of "amount" in the collection which is the 4th level deeper laravel collection. How do I change the "amount" value in laravel collection. Help much appreciated.

0 likes
0 replies

Please or to participate in this conversation.