【发布时间】:2017-11-08 06:28:21
【问题描述】:
我正在使用 Crinsane 购物车,我试图将图像传递给购物车,但是 我有错误
传递给 Gloudemans\Shoppingcart\Cart::add() 的参数 5 必须是 类型数组,给定字符串,调用 E:\phalwalatheme\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php 在第 221 行
CartController.php
public function addItem($id)
{
$products=Products::find($id);
Cart::add($id,$products->name, $products->image ,1,$products->price);
return back();
}
cart.blade.php
<td class="product-thumbnail">
<img src="{{url('images/product',$cartItem->image)}}" alt="product-thumbnail">
</td>
当我评论 $products->image 时,一切正常。并且 img div 也显示“alt”输出。我也使用过{{ $product->image}} 和array($products->image)。但它们都不起作用。
【问题讨论】:
-
我认为你需要这样尝试:
Cart::add(array('id' => $id, 'name' => $products->name 'qty' => 1, 'price' => $products->price));希望这对你有帮助!! -
但我仍然如何声明图像???
-
Cart::add(array('id' => $id, 'name' => $products->name, 'qty' => 1, 'price' => $products->price, 'image' => $products->image));试试这个,可能有用! -
是的,我没有出错,但没有显示静止图像。
-
如果这解决了您的问题,请支持
Argument 5 passed to Gloudemans\Shoppingcart\Cart::add() must be of the type array, string given