public function new($product_id, Request $request) { // get or create cart if (!Session::get('cart_id')) { $cart = CartsController::new(); $cart_id = $cart->id; Session::put('cart_id', $cart_id); } else { $cart_id = Session::get('cart_id'); } //get product data for cart item $product = Product::whereId($product_id)->firstOrFail(); $cartitem = new CartItem(['cart_id' => $cart_id, 'product_id' => $product->id, 'qty' => $request->get('qty'), 'price_ea' => $product->price, 'price_total' => $product->price * $request->get('qty')]); $cartitem->save(); $request->session()->flash('status', 'Item added to cart!'); return redirect('/'); }