app/Http/Controllers/SanPhamController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function updateCart(Request $request)
    {
        if($request->id && $request->quantity)
        {
            $cart = session()->get('cart');
            $sanpham = sanPham::findOrFail($request->id);
            if($sanpham->soluongton>=$request->quantity):
                $cart[$request->id]["quantity"] = $request->quantity;
                session()->put('cart', $cart);
                session()->flash('success', 'Cart updated successfully');
            else:
                session()->flash('errors', 'Tồn kho không đủ số lượng');
            endif;
        }
    }
public function updateCart ( Request $ request ) { if ( $ request -> id && $ request -> quantity ) { $ cart = session ( ) -> get ( 'cart' ) ; $ sanpham = sanPham :: findOrFail ( $ request -> id ) ; if ( $ sanpham -> soluongton >= $ request -> quantity ) : $ cart [ $ request -> id ] [ " quantity " ] = $ request -> quantity ; session ( ) -> put ( 'cart' , $ cart ) ; session ( ) -> flash ( 'success' , 'Cart updated successfully' ) ; else : session ( ) -> flash ( 'errors' , 'Tồn kho không đủ số lượng'); endif ; } }
Update the specified resource in storage.
Update the specified resource in storage .