jhutto
261
9
General

Access Json Array item located at 3rd level down in the array to show in view

Posted 1 year ago by jhutto

I'm a newbie to laravel and I'm importing an Json Array from an API. The array has many levels of arrays.. (Below). I'm trying to get access to the Address in the array to show in my view. The array is a record of a person and the address buried in the array. I'm also including my code from page trying to load the item.

This line below gives me an Undefined index: address1...

{{$person['addresses']['address']['address1']}}

array:1 [▼ "results" => array:5 [▼ "@count" => "2" "@pageNumber" => "1" "@totalRecords" => "2" "@additionalPages" => "0" "person" => array:2 [▼ 0 => array:40 [▼ "@id" => "1075735630" "@uri" => "https://milehi.staging.fellowshiponeapi.com/v1/People/1075735630" "@imageURI" => "" "@oldID" => "" "@iCode" => "wo4QwInnbVOPIAc+XntOPg==" "@householdID" => "1046185397" "@oldHouseholdID" => "" "title" => null "salutation" => null "prefix" => null "firstName" => "Jack" "lastName" => "Siegman" "suffix" => null "middleName" => null "goesByName" => null "formerName" => null "gender" => null "dateOfBirth" => null "maritalStatus" => null "householdMemberType" => array:3 [▶] "isAuthorized" => "true" "status" => array:6 [▶] "occupation" => array:4 [▶] "employer" => null "school" => array:3 [▶] "denomination" => array:3 [▶] "formerChurch" => null "barCode" => null "memberEnvelopeCode" => null "defaultTagComment" => null "weblink" => array:3 [▶] "solicit" => null "thank" => "true" "firstRecord" => "2016-02-04T09:06:17" "attributes" => null "addresses" => array:1 [▼ "address" => array:1 [▼ 0 => array:22 [▼ "@id" => "1042967710" "@uri" => "https://milehi.staging.fellowshiponeapi.com/v1/Addresses/1042967710" "household" => array:2 [▶] "person" => array:2 [▶] "addressType" => array:3 [▶] "address1" => "413 Butterfield Trl" "address2" => null "address3" => null "city" => "Edmond" "postalCode" => "73003" "county" => null "country" => "US" "stProvince" => "OK" "carrierRoute" => null "deliveryPoint" => null "addressDate" => null "addressComment" => null "uspsVerified" => "false" "addressVerifiedDate" => null "lastVerificationAttemptDate" => null "createdDate" => "2016-02-04T09:06:37" "lastUpdatedDate" => "2016-02-04T09:06:38" ] ] ] "communications" => null "lastMatchDate" => null "createdDate" => "2016-02-04T09:06:18" "lastUpdatedDate" => "2016-02-04T09:06:22" ] 1 => array:40 [▶] ] ] ]

Id Name Address Status
    <th style="width: 20%">Select</th>
   </tr>
 </thead>

@if($r && $r['results']['@count']>0) @foreach($r['results']['person'] as $person)

{{$person['@id']}} {{$person['firstName']}} {{$person['lastName']}} {{$person['addresses']['address']['address1']}} {{$person['status']['name']}}   Select   @endforeach @endif

Please sign in or create an account to participate in this conversation.