0
votes

I've encountered this problem (

Cannot use object of type __PHP_Incomplete_Class as array

) while doing an e-commerce site using Laravel, I tried to get the name of the purchased products. My controller function is this

$orders=Auth::user()->orders;

$orders->transform(function($orders, $key) { $orders->cart=unserialize($orders->cart);

return $orders;
});

return view('shop.profile', ['orders'=>$orders]);

The problem in the view code is this exact line {{$item['item']['name']}}, without it, i can see the quantity puchased, the price and anything else.

I've done everything I knew and found on the internet, but didn't find any solution

1
Can you show the code in the view as well? It is a little unclear what data you are interested in, but i think the view-code would help. - Rob Biermann
<h2 align="center">My orders</h2> <br/> @foreach($orders as $order) <div class="panel panel-default"> <div class="panel-body"> <ul class="list-group"> @foreach($order->cart->items as $item) <li class="list-group-item"> <span class="badge">{{$item['price']}} lei</span> {{$item['item']['name']}} | {{$item['qty']}} </li> @endforeach </ul> </div> <div class="panel-footer"><strong>Total Price: {{$order->cart->totalPrice}} lei </strong></div> </div> @endforeach - Sandra

1 Answers

0
votes

Based on your information, i would assume you could use a solution like this:

<h2 align="center">My orders</h2> <br/>
@foreach($orders as $order)
    <div class="panel panel-default">
        <div class="panel-body">
            <ul class="list-group">
                @foreach($order->cart->items as $item)
                    <li class="list-group-item">
                        <span class="badge">{{$item->price}} lei</span> 
                        {{$item->item->name }} | {{$item->qty }} 
                    </li>
                @endforeach
            </ul>
        </div>
        <div class="panel-footer"><strong>Total Price: {{$order->cart->totalPrice}} lei </strong></div>
    </div>
@endforeach

Normally, you do not talk to the $items like an array, but like an object. I believe this should do the trick, please let me know if it worked :)