[英]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.