how to access protected array values ?

后端 未结 1 1333
粉色の甜心
粉色の甜心 2021-01-18 00:21

Hi I have this array and I am not sure how will I fetch the name , brand, image, token values from it?

Gloudemans\\Shoppingcart\\CartCollection Object
(
  [i         


        
相关标签:
1条回答
  • 2021-01-18 00:56

    save the object in a variable and do a foreach loop,

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

    if that's not working, 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're using has a alternate method search

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

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

    0 讨论(0)
提交回复
热议问题