0

I would like to access to a value from an array response, but I get null or an exception "Trying to get property of non object".

Here is my array:

array:5 [▼
  677 => array:4 [▶]
  676 => array:4 [▶]
  675 => array:4 [▶]
  674 => array:4 [▶]
  673 => array:4 [▶]
]

I would like to get each id foreach items

array:5 [▼
  677 => array:4 [▼
    "qty" => 1
    "montant" => "25.00"
    "item" => Licencies {#961 ▼
      #table: "licencies"
      ...
      #attributes: array:46 [▶]
      #original: array:46 [▼
        "id" => 677

Here my actual controller

foreach ($items as $item) {
    $item = $item;
    dd($item);
}

When I do $item = $item->id to get the id of the object, I get "trying to get property of non object"

What should I do?

1 Answer 1

1

Looks like $item is an array too. Try using the array syntax:

foreach ($items as $item) {

    $item = $item['id'];
}
Sign up to request clarification or add additional context in comments.

1 Comment

Update your question with further details of your current problem.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.