mardi 2 juin 2020

Nested eager loading on laravel result collection

Is there anyway to do eager loading on laravel 5.3 result collection in nested array data? Below is my result (after putting toArray() on result) where FORM_JSON is array format after typecasting from json. I want to put condition on laravel result data to filter out those records where FORM_JSON->house->window.*-> status = Removed. Where window's status is removed condition with eager loading, not for-each-loop.

Array(
[0] => Array(
    [ID] => 4
    [FORM_JSON] => Array(
        [id] => 1
        [house] => Array(
            [window] => Array(
                [0] => Array(
                    [appliance_id] => 1
                    [status] => Completed
                )
                [1] => Array(
                    [appliance_id] => 2
                    [status] => Removed
                )
                [2] => Array(
                    [appliance_id] => 2
                    [status] => Removed
                )
                [3] => Array(
                    [appliance_id] => 2
                    [status] => Removed
                )
            )
            [final_report] => Array(
                [pipework_install] => No
                [general_comments] => test
            )
        )
    )
    [PROPERTY_NAME] => property name goes here
)

[1] => Array(
    [ID] => 5
    [FORM_JSON] => Array(
        [id] => 1
        [house] => Array(
            [window] => Array(
                [0] => Array(
                    [appliance_id] => 1
                    [status] => Removed
                )
                [1] => Array(
                    [appliance_id] => 5
                    [status] => Completed
                )
            )
            [final_report] => Array(
                [pipework_install] => Yes
                [general_comments] => no comments
            )
        )
    )
    [PROPERTY_NAME] => property name goes here
)

)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire