skip to Main Content
{
    "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 class="list-group-item d-flex flex-wrap justify-content-between">
        <span>
            ucFirst($key)
        </span>
        <span class="text--info font-weight-bold">
{{ $key()?['value'] }}
        </span>
    </li>
@endforeach

displaying the key works but not the value child

how should i do it so that it works??

2

Answers


  1. Chosen as BEST ANSWER

    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 class="list-group-item d-flex flex-wrap justify-content-between">
                                                <span>
                                                    @lang(ucFirst($key))
                                                </span>
                                                <span class="text--info font-weight-bold">
                                                    {{ $item->value }}
                                                </span>
                                            </li>
                                        @endforeach
                                    @endif
    

  2. @foreach ($transfer->beneficiary->details as $key => $item)
        <li class="list-group-item d-flex flex-wrap justify-content-between">
            <span>
                ucFirst($key)
            </span>
            <span class="text--info font-weight-bold">
                {{ $item['value'] }}
            </span>
        </li>
    @endforeach
    

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search