Home > Enterprise >  How to get a item in an object which is in another object
How to get a item in an object which is in another object

Time:12-15

{
    "swift":
        {
            "type":"text",
            "value":"WF0987"
        },
    "routing_number":
        {
            "type":"text",
            "value":"8402984302"
        },
    "bank_address":
        {
            "type":"text",
            "value":"BullDog 57483, USA"
        },
    "purpose_of_transfer":
        {
            "type":"text",
            "value":"FAMILY SUPPORT"
        }
}

i have an obj inside another obj i want to retrieve the value of each key

this is my solution

@foreach ($transfer->beneficiary->details as $key => $item)
    <li >
        <span>
            ucFirst($key)
        </span>
        <span >
{{ $key()?['value'] }}
        </span>
    </li>
@endforeach

displaying the key works but not the value child

how should i do it so that it works??

CodePudding user response:

This worked for me {{ $item->value }} thanks to @Barmar for his contribution

so this was my final code

    @if($transfer->beneficiary->details)
                                    @foreach ($transfer->beneficiary->details as $key => $item)
                                        <li >
                                            <span>
                                                @lang(ucFirst($key))
                                            </span>
                                            <span >
                                                {{ $item->value }}
                                            </span>
                                        </li>
                                    @endforeach
                                @endif

CodePudding user response:

@foreach ($transfer->beneficiary->details as $key => $item)
    <li >
        <span>
            ucFirst($key)
        </span>
        <span >
            {{ $item['value'] }}
        </span>
    </li>
@endforeach

You can also use the -> operator to access the value property like this: {{ $item->value }}

  • Related