Crinsane / LaravelShoppingcart

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

Error Object of class Gloudemans\Shoppingcart\CartItem could not be converted to string (View: C:\Users\Alasco\Desktop\laravel\e_shop\resources\views\livewire\cart-component.blade.php) #656

Open LepetitHero opened 3 years ago

LepetitHero commented 3 years ago

Hi ! I've a new issue from my code. When I try to add product to the cart, I get this issue.

this the controller

`use Cart;

public function store($product_id, $product_name, $product_price) { Cart::add($product_id, $product_name,1, $product_price)->associate('App\Models\Product'); session()->flash('success_message', 'item add in cart'); return redirect()->route('product.cart'); }`

this this the view code `

            @if (Session::has('success_message'))

                <strong>Success</strong> {{Session::get('success_message')}}

            @endif

            @if (Cart::count() > 0)

            <h3 class="box-title">Products Name</h3>

            <ul class="products-cart">

                @foreach (Cart::content() as $item )

                <li class="pr-cart-item">

                    <div class="product-image">

                        <figure><img src="{{ asset('assets/images/products') }}/{{$item->model->image}}" alt="{{$item->model->name}}"></figure>

                    </div>

                    <div class="product-name">

                        <a class="link-to-product" href="{{route('product.details',['slug'->$item->model->slug])}}">{{$item->model->name}}</a>

                    </div>

                    <div class="price-field produtc-price"><p class="price">${{$item->model->regular_price}}</p></div>

                    <div class="quantity">

                        <div class="quantity-input">

                            <a class="btn btn-increase" href="#"></a>

                            <input type="text" name="product-quatity" value="{{$item->qty}}" data-max="120" pattern="[0-9]*">

                            <a class="btn btn-reduce" href="#"></a>

                        </div>

                    </div>

                    <div class="price-field sub-total"><p class="price">${{$item->subtotal}}</p></div>

                    <div class="delete">

                        <a href="#" class="btn btn-delete" title="">

                            <span>Delete from your cart</span>

                            <i class="fa fa-times-circle" aria-hidden="true"></i>

                        </a>

                    </div`

Please, I need your help. Thanks!!