为什么我在Laravel中遇到此错误?错误:-函数Darryldecode \ Cart \ Cart :: updateQuantityRelative的参数太少

问题描述

我收到此错误:

ArgumentCountError 函数Darryldecode \ Cart \ Cart :: updateQuantityRelative()的参数太少,第261行传递了.. \ vendor \ laravel \ framework \ src \ Illuminate \ Support \ Facades \ Facade.php中的1个,正好是3个(查看:。 .. \ resources \ views \ cart.blade.php)

cart.blade.php

@foreach(\Cart::session(auth()->id())->getContent() as $items)
   <tr>
     <td class="text-center">
       <a href="{{ route('cart.destroy',$items->id)}}">x</a>
       </td>
        <td data-title="Product">
          <a href="#" class="text-gray-90">{{ $items ['name'] }}</a>
        </td>
       <td data-title="Price">
          <span class="">LKR {{ $items ['price'] }}.00</span>
       </td>
       <td data-title="Quantity">
            <span class="sr-only">Quantity</span>
       <!-- Quantity -->
               <div class="border rounded-pill py-1 width-122 w-xl-80 px-3 border-color-1">
                  <div class="js-quantity row align-items-center">
                      <div class="col">
                          <input class="js-result form-control h-auto border-0 rounded p-0 shadow-none" type="text" value="{{ \Cart::updateQuantityRelative($items->quantity) }}">
                        </div>
                         <div class="col-auto pr-1">
                              <a class="js-minus btn btn-icon btn-xs btn-outline-secondary rounded-circle border-0" href="javascript:;">
                                  <small class="fas fa-minus btn-icon__inner"></small>
                                </a>
                               <a class="js-plus btn btn-icon btn-xs btn-outline-secondary rounded-circle border-0" href="javascript:;">
                                    <small class="fas fa-plus btn-icon__inner"></small>
                                  </a>
                              </div>
                            </div>
                         </div> 
       <!-- End Quantity -->
      </td>
      <td data-title="Total">
          <span class="">
               {{ $items -> getPriceSum()}}
            </span>
        </td>
  </tr>
@endforeach

CartController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Product;
use App\Category;
use Darryldecode\Cart\Cart;

class CartController extends Controller
{
    public function index()
    {
        return view ('cart');
    }
   
    public function show($id)
    {
        $product = Product::find($id);
        return view('cart')->with(compact('product'));
    }
   
    public function destroy($itemId)
    {
       return back();
    }

    public function addtocart(Product $product)
    {
    
        \Cart::session(auth()->id())->add(array(
            'id' => $product->id,'name' => $product->prod_name,'price' => $product->prod_price,'quantity' => 1,'attributes' => array(),'associatedModel' => $product
        ));

        return redirect()->back();
    }
}

我安装了 Darryldecode 购物车程序包。

updateQuantityRelative函数已在其中定义。

public function updateQuantityRelative($item,$key,$value)
{
    if (preg_match('/\-/',$value) == 1) {
        $value = (int)str_replace('-','',$value);

        // we will not allowed to reduced quantity to 0,so if the given value
        // would result to item quantity of 0,we will not do it.
        if (($item[$key] - $value) > 0) {
            $item[$key] -= $value;
        }
    } elseif (preg_match('/\+/',$value) == 1) {
        $item[$key] += (int)str_replace('+',$value);
    } else {
        $item[$key] += (int)$value;
    }

    return $item;
}

我认为以下代码需要更正。应该如何?

value="{{ \Cart::updateQuantityRelative($items->quantity) }}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)