vendredi 27 mars 2020

Laravel collection advanced filter

{
    {
        id: 125,
        cars: [
            {
                model: 5,
                address: {
                    city_id: 3
                }
            },
            {
                model: 1,
                address: {
                    city_id: 3
                }
            }
        ]
    },
    {
        id: 124,
        cars: [
            {
                model: 5,
                address: {
                    city_id: 1
                }
            },
            {
                model: 5
                address: {
                    city_id: 3
                }
            }
        ]
    },
    {
        id: 127,
        cars: [
            {
                model: 10,
                address: {
                    city_id: 1,
                }
            },
            {
                model: 9,
                address: {
                    city_id: 8
                }
            }
        ]
    }
}

Now I want to filter this collection by city_id == 3. Shortly I want this as a result:

{
    {
        id: 125,
        cars: [
            {
                model: 5,
                address: {
                    city_id: 3
                }
            }
        ]
    },
    {
        id: 124,
        cars: [
            {
                model: 5,
                address: {
                    city_id: 3
                }
            }
        ]
    }
}

I use Laravel 6. I want to build a filter car by address. I use Laravel 6. I want to build a filter car by address. I use Laravel 6. I want to build a filter car by address. I use Laravel 6. I want to build a filter car by address. I use Laravel 6. I want to build a filter car by address. I use Laravel 6. I want to build a filter car by address. I use Laravel 6. I want to build a filter car by address. I use Laravel 6. I want to build a filter car by address. I use Laravel 6. I want to build a filter car by address.

Please help me. How can I filter?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2wFU3mg
via IFTTT

Aucun commentaire:

Enregistrer un commentaire