0
{`
+"insights": array:1 [▼
    0 => {#209 ▼
      +"group": "Provision"
      +"dataset": array:1 [▼
        0 => {#207 ▼
          +"group": "Provision"
          +"set": array:3 [▼
            0 => {#194 ▼
              +"name": "Neutral"
              +"value": 917
            }
            1 => {#203 ▶}
            2 => {#197 ▶}
          ]
        }
      ]
    }
  ]
  +"errorCode": 0
}`

How to get the name property inside the set array? I've tried multiple way but it kept error return trying to get property non-object.

3
  • 3
    Have you tried anything. Accessing objects properties you should search. Commented May 28, 2018 at 6:32
  • Post the code which you tried so SO can help in that. Commented May 28, 2018 at 6:37
  • I'm sorry about the lack of info in my question. Originally I was retrieving data so it was returned in JSON format, then I used something like this $data = $json_decode($response) then dd($data). I've tried accessing the object properties but maybe i do it wrong. Commented May 28, 2018 at 6:40

3 Answers 3

2

suppose you provide $response to your blade view

$response =    {
    +"insights": array:1 [▼
        0 => {#209 ▼
          +"group": "Provision"
          +"dataset": array:1 [▼
            0 => {#207 ▼
              +"group": "Provision"
              +"set": array:3 [▼
                0 => {#194 ▼
                  +"name": "Neutral"
                  +"value": 917
                }
                1 => {#203 ▶}
                2 => {#197 ▶}
              ]
            }
          ]
        }
      ]
      +"errorCode": 0
    }

You have to loop through to response , in your blade view :

@foreach($response->insights as $insight)
   @foreach($insight['dataset'] as $dataset)
       @foreach($dataset['set'] as $set)
           <tr><td>$set['name']</td></tr>
       @endforeach
   @endforeach
@endforeach
Sign up to request clarification or add additional context in comments.

Comments

1
data_get($data, 'insights.0.dataset.0.set.0.name');

end if you have json - convert it into array -> json_decode(string);

2 Comments

Can u explain a bit about this?
Each dot is a nest in the array. The downside of this method vs Saurabh 's is you have to known which sub-arrays there are and in which key it is. You can check this link for more info on array dot notation
1

You have to simply loop through it and do whatever you want to with that name,

foreach($response->insights as $temp){
   foreach($temp->dataset as $var){
      foreach($var as $obj){
         $name = $obj->name;
      }
   }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.