How to access protected array values?

Hi, I have this array and I'm not sure how to get the name, brand, image, tokens from it?

Gloudemans\Shoppingcart\CartCollection Object ( [items:protected] => Array ( [1264477c2182cc04a63fde1186741fa7] => Gloudemans\Shoppingcart\CartRowCollection Object ( [associatedModel:protected] => [associatedModelNamespace:protected] => [items:protected] => Array ( [rowid] => 1264477c2182cc04a63fde1186741fa7 [id] => 1 [name] => washington apples [qty] => 1 [price] => 90 [options] => Gloudemans\Shoppingcart\CartRowOptionsCollection Object ( [items:protected] => Array ( [brand] => awesome apple [image] => C:\xampp\htdocs\srsgrocery\storage/app/products/1/apple-06.jpg [token] => WiQgUjqgHEB3HZ2ImJ6iPQWHnm246twFD3Uyk6AH ) ) [subtotal] => 90 ) ) ) 

)

I am using a php framework called laravel.
Please help.

+5
source share
1 answer

save the object in a variable and execute a foreach ,

 foreach($cart as $item) { echo $item->name; echo $item->options->brand; } 

If this does not work, you can use the fetch method from the collection class.

http://laravel.com/api/5.0/Illuminate/Support/Collection.html#method_fetch

 $item->fetch('name'); 

and the package you use has an alternative search method

 $item->search('name'); $item->search(['options' => 'name']) 

https://github.com/Crinsane/LaravelShoppingcart/blob/master/src/Gloudemans/Shoppingcart/CartRowOptionsCollection.php

+2
source

Source: https://habr.com/ru/post/1238747/


All Articles