第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Laravel 錯(cuò)誤:調(diào)用未定義的方法 App\Cart::delete()

Laravel 錯(cuò)誤:調(diào)用未定義的方法 App\Cart::delete()

PHP
慕容708150 2023-07-08 21:00:33
我正在嘗試激活購(gòu)物車(laravel 項(xiàng)目)上的刪除按鈕。實(shí)現(xiàn)函數(shù) destroy 后,我遇到了錯(cuò)誤Call to undefined method App\Cart::delete()。根據(jù)我的觀點(diǎn),我也嘗試{{ route('cart.destroy', ['id' => $product['item']['id']]) }}過我的觀點(diǎn),但仍然是一樣的。似乎沒問題,但我不知道該怎么辦,我對(duì)此很困惑。購(gòu)物車:php<?phpnamespace App;class Cart {   public $items = null;   public $totalQty = 0;   public $totalPrice = 0;   public function __construct($oldCart)   {     if ($oldCart) {        $this->items = $oldCart->items;        $this->totalQty = $oldCart->totalQty;        $this->totalPrice = $oldCart->totalPrice;     }   }   public function add($item, $id)   {     $storedItem = ['qty' => 0, 'price' => $item->price, 'item' => $item, 'imagePath' => $item->imagePath];     if ($this->items ) {            if (array_key_exists($id, $this->items)) {                 $storedItem = $this->items[$id];             }         }         $storedItem['qty']++;         $storedItem['price'] = $item->price * $storedItem['qty'];         $storedItem['imagePath'] = $item->imagePath;         $this->items[$id] = $storedItem;         $this->totalQty++;         $this->totalPrice += $item->price;    }}購(gòu)物車控制器.php:class ProductController extends Controller{    /**    *@return \Illuminate\Http\Response    */    public function index()    {        $products = Product::all();        return view('home', ['products'=> $products]);    }    public function getAddToCart(Request $request, $id)     {        $product = Product::find($id);        $oldCart = Session::has('cart') ? Session::get('cart') : null;        $cart = new Cart($oldCart);        $cart->add($product, $product->id);                $request->session()->put('cart', $cart);        return redirect()->route('home');    }    public function getCart()    {        if (!Session::has('cart')) {            return view('cart');        }        $oldCart = Session::get('cart');        $cart = new Cart($oldCart);         return view('cart', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice]);    }
查看完整描述

1 回答

?
PIPIONE

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊

您的 Cart 類中沒有刪除功能。您需要?jiǎng)?chuàng)建一個(gè)。



查看完整回答
反對(duì) 回復(fù) 2023-07-08
  • 1 回答
  • 0 關(guān)注
  • 185 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)