简体   繁体   English

当我点击添加到购物车按钮时会发生什么我在 laravel 中遇到了一些错误?

[英]what happens when i click add to cart button i am facing some error in laravel?

What happens when i click add to cart button how to fix this error using laravel ?当我单击添加到购物车按钮时会发生什么如何使用 laravel 修复此错误?

Please see this error Argument 5 passed to Gloudemans\\Shoppingcart\\Cart::add() must be of the type array, string given, called in C:\\xampp\\htdocs\\Projects\\E-commerce\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Facades\\Facade.php on line 245请参阅此错误参数 5 传递给 Gloudemans\\Shoppingcart\\Cart::add() must be of the type array, string given, 在 C:\\xampp\\htdocs\\Projects\\E-commerce\\vendor\\laravel\\framework\\src 中调用\\Illuminate\\Support\\Facades\\Facade.php 第 245 行

https://flareapp.io/share/xmN6yEm0 https://flareapp.io/share/xmN6yEm0

Controller控制器

        public  function addcart(Request $request)
        {
        Cart::add($request->productid,$request->product_name,$request->qty,$reques- 
        >product_image,$request->product_price);
        return redirect()->route('cart.index')->with('successmessage','Items added successfully');
         }

html view html视图

            <form action="{{route('cart.action')}}" method="post" class="product__options">
             {{ csrf_field() }}

            <input type="hidden" name="productid" value="{{$single_products->id}}">
            <input type="hidden" name="product_name" value="{{$single_products->product_name}}">
            <input type="hidden" name="product_image" value="{{$single_products- 
             >product_image}}">
             <input type="hidden" name="product_brand" value="{{$single_products->product_brand}}">
             <input type="hidden" name="product_price" value="{{$single_products->product_price}}">

                <div class="form-group product__option">
                <label class="product__option-label" for="product-quantity">Quantity</label>
                <div class="product__actions">
                <div class="product__actions-item">
                <div class="input-number product__quantity">
                <input id="product-quantity" name="qty" class="input-number__input form-control 
                 form-control-lg" type="number" min="1" value="1">
                <div class="input-number__add"></div>
                <div class="input-number__sub"></div>
                </div>
                </div>
                <div class="product__actions-item product__actions-item--addtocart">
                <button class="btn btn-primary btn-lg">Add to cart</button>
                </div>
                <div class="product__actions-item product__actions-item--wishlist">
                <button type="button" class="btn btn-secondary btn-svg-icon btn-lg" data-toggle="tooltip" title="Wishlist">
                <svg width="16px" height="16px">
                <use xlink:href="{{url('public/assets/images/sprite.svg#wishlist-16')}}"></use>
                </svg>
                </button>
                </div>
                <div class="product__actions-item product__actions-item--compare">
                <button type="button" class="btn btn-secondary btn-svg-icon btn-lg" data- 
                 toggle="tooltip" title="Compare">
                <svg width="16px" height="16px">
                <use xlink:href="{{url('public/assets/images/sprite.svg#compare-16')}}"></use>
                </svg>
                </button>
                </div>
                </div>
                </div>
                </form>

,Actually the Cart::add method takes price on fourth parameter and fifth parameter is for options where you can pass array of options ,实际上Cart::add方法在第四个参数上取价格,第五个参数用于您可以传递选项数组的选项

for example:例如:

Cart::add(['id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'options' => ['size' => 'large']]);

What you can do is modify your function like this and it should work, hopefully:你可以做的是像这样修改你的函数,它应该可以工作,希望:

public function addcart(Request $request){
    $image = [$request->product_image];
    Cart::add($request->productid,$request->product_name,$request->qty,$request->product_price,$image);
    return redirect()->route('cart.index')->with('successmessage','Items added successfully');
}

I hope it'll help you.我希望它会帮助你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想使用laravel单击“添加到购物车”按钮时,将商品显示在购物车中吗? - I Want to show products items into shopping cart when i click add to cart button using laravel? 我正面临laravel 5路由 - I am facing laravel 5 routing 想显示投资组合图片,但我遇到了一些错误 - want to show portfolio images but i am facing some error laravel 7 当我单击注册按钮时没有任何反应,似乎没有触发事件 - laravel 7 nothing happens when i click sign up button it seems like event is not triggering 如果我单击已在购物车中的产品的“添加到购物车”按钮,如何重定向到购物车页面 - How do I redirect to the cart page if I click on the 'Add to cart' button for a product that's already in cart 当我在代码中单击添加到购物车时,我得到的值相同。 这是PHP中的ajax响应 - I am getting the same value when I click on add to cart in my code. It's an ajax response in php 我在php laravel中遇到复选框问题 - i am facing an issue with checkbox in php laravel 在Google Apps引擎上运行项目时遇到错误 - I am facing error when run a project at google apps engine 为什么我在 Laravel 中收到此错误? 错误:-arguments 到 function Darryldecode\Cart\Cart::updateQuantityRelative() 太少 - Why I am getting this error in Laravel? Error:-Too few arguments to function Darryldecode\Cart\Cart::updateQuantityRelative() 当我在magento的购物车中添加产品时,出现错误“以下某些产品没有所有必需的选项” - getting error “Some of the products below do not have all the required options” when i add product in cart in magento
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM