Nikki
7 months ago

Trying to get property 'items' of non-object

Posted 7 months ago by Nikki

I'm trying to get a list of the items in my cart, I serialized the cart and added it to my database. The problem I have is that when I try to loop through my cart I get this error

Trying to get property 'items' of non-object

If I dd($order->cart->items); then at least 1 cart shows up, so I'm not getting why I'm recieving the error .

My function

public function trackOrders()
{
    $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
    $contacts = Contact::all();

    $orders = Auth::user()->orders;
    $orders->transform(function($order, $key){
        $order->cart = unserialize($order->cart);
        return $order;
    });

    return view('public.users.track-orders', compact('menus_child', 'contacts', 'orders'));
}

My blade

@foreach($orders as $order)
    <div class="row">
        <div class="col-lg-12">
            <div class="card mt-15">
                <div class="card-header">
                    <div class="invoice-details">
                        <div>
                            {{ Carbon\Carbon::now() }}

                            ARM0001 | Ordered: {{ Carbon\Carbon::parse($order->order_date)->format('d F Y') }} | Paid: Add Paid date
                        </div>
                        <div>
                            Delivered: {{ Carbon\Carbon::parse($order->delivered_date)->format('d F Y') }}
                        </div>
                    </div>

                    <div class="invoice-buttons">
                        <a href="#" class="btn btn-primary">Track Order</a> | 
                        <a href="#" class="btn btn-primary">Order Details</a>
                    </div>
                </div>

                <div class="card-body">
                    <div class="row text-center">
                        @foreach($order->cart->items as $item)
                            {{ $item['item']['title'] }}
                        @endforeach
                    </div>
                </div>
            </div>
        </div>
    </div>
@endforeach

If there is anything else that I need to provide please let me know

Please sign in or create an account to participate in this conversation.