简体   繁体   中英

my cart value not store in cart session in laravel

  • I am currently working on e commerce project. I am unable to create a session or store cart value in session below is the code snippet:
  • Technology Used : Php Laravel 6

    namespace App\\Http\\Controllers; use App\\Http\\Controllers\\Controller; use Illuminate\\Support\\Facades\\DB; use Illuminate\\Http\\Request; use App\\Product; use Session; use Auth; class CartController extends Controller { public function addedtocart(Request $request){ $id=$request->proid; $quantity=$request->quantity; $product = Product::find($id); $cart = $request->session()->get('cart'); if(isset($cart[$product['Product_ID']])): $cart[$product['Product_ID']]['qty'] += $quantity; else: $cart[$product['Product_ID']] = $product; $cart[$product['Product_ID']]['qty'] = $quantity; endif; Session::push('cart',$cart); return view('frontend.cart.addedtocart',compact('product'));
    } }

Could you please anyone help to me?

我只能推荐你https://github.com/Crinsane/LaravelShoppingcart包它会让你的生活更轻松!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM