\Symfony\Component\Debug\Exception\FatalThrowableError
传递给Darryldecode\Cart\Cart::Darryldecode\Cart{closure}()的参数%1必须是Darryldecode\Cart\CartCondition的实例,给定的是Darryldecode\Cart\ItemCollection的实例
C:\wamp64\www\blog\vendor\darryldecode\cart\src\Darryldecode\Cart\Cart.php:589
我刚刚做了composer dumpautoload,在那之后,当我去http://localhost/ecom/public/cart的时候,我得到了这个错误。我使用的是达瑞斯解码卡特库。在dumpload之前,购物车工作正常。
Cart Create函数工作正常,但没有索引
public function index()
{
$cartSubTotal = Cart::getSubTotal();
$condition = new \Darryldecode\Cart\CartCondition(array(
'name' => 'GST',
'type' => 'tax',
'target' => 'total',
'value' => '5%',
'attributes' => array( // attributes field is optional
'description' => 'Goods & Services Tax',
'more_data' => 'It is 5% of the total Value'
)
));
$cartTotal = Cart::getTotal();
$gst = $cartSubTotal * 0.05;
$datas = Cart::getContent();
//$product = Products::whereIn('id', $datas->pluck('id')->all())->get();
return view('cart.index', compact('datas','cartSubTotal','gst','cartTotal','condition'));
}发布于 2020-07-05 20:41:21
使用Darryl中的示例代码也遇到了同样的问题。CacheStorage工作正常,但切换到DatabaseStorage时出现错误。
因为我不使用条件,所以DbStorage中的这个简单的修复将为我做:
public function get($key)
{
$cart = $this->has($key);
if($cart)
{
if (str_contains($key,'conditions')) {
return $cart->conditions; // return empty array
}
else {
return new CartCollection($cart->cart_data);
}
}
else
{
return new CartCollection([]);
}
}https://stackoverflow.com/questions/60247328
复制相似问题