Crinsane / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
3.67k stars 1.73k forks source link

Problem in Cart::content() in foreach #578

Open DevHP03 opened 5 years ago

DevHP03 commented 5 years ago

When I use the Cart:: content() as $item in foreach for set the href for example

   @foreach(Cart::content() as $item)
                    <tr class="cart-table__row" style="background-color: white">
                        <td class="cart-table__column cart-table__column--image">
                            <a href="{{ route('shop.show',$item->model->slug,$item->model->name) }}"><img src="{{ asset('front/images/products/medium/'.$item->model->image) }}" alt=""></a>
                        </td>
                        <td class="cart-table__column cart-table__column--product"><a href="" class="cart-table__product-name">اره برقی برندیکس مدل 300 وات</a>
                            <ul class="cart-table__options">
                                <li>رنگ: زرد</li>
                                <li>جنس: آلومینیوم</li>
                            </ul>
                        </td>
                        <td class="cart-table__column cart-table__column--price" data-title="قیمت">699,000 تومان</td>
                        <td class="cart-table__column cart-table__column--quantity" data-title="تعداد">
                            <div class="input-number">
                                <input class="form-control input-number__input" type="number" min="1" value="2">
                                <div class="input-number__add"></div>
                                <div class="input-number__sub"></div>
                            </div>
                        </td>
                        <td class="cart-table__column cart-table__column--total" data-title="جمع کل">1,398,000 تومان</td>
                        <td class="cart-table__column cart-table__column--remove">
                            <button type="button" class="btn btn-light btn-sm btn-svg-icon">
                                <svg width="12px" height="12px">
                                    <use xlink:href="images/sprite.svg#cross-12"></use>
                                </svg>
                            </button>
                        </td>
                    </tr>
                @endforeach

When the cart is empty everything right but when I add a product to the cart the error says

Trying to get property 'slug' of non-object (View: C:\xampp\htdocs\ACode\projectweb\Karajelectronic\karajelectronic-shop\resources\views\front\cart.blade.php)

markdenverPH commented 5 years ago

I'm still new to Laravel, but that's not how I access arrays in blade.php files. Try doing this: $this['model']['slug] If it's not working, try checking the values of $item or $item['model'] by putting {{ dd($item) }} below @foreach(..)

Iconbanderas commented 5 years ago

The Cart::content() array is not working. It does not loop over the cart content. You can see here it says 9 items in the cart and yet it does not loop over

image