public function checkout(Request $request) { $token = $request->input('stripeToken'); //Retriieve cart information $cart = Cart::where('user_id', Auth::user()->id)->first(); $items = $cart->cartItems; $total = 0; foreach ($items as $item) { $total += $item->product->price; } if (Auth::user()->charge($total * 100, ['source' => $token, 'receipt_email' => Auth::user()->email])) { $order = new Order(); $order->total_paid = $total; $order->user_id = Auth::user()->id; $order->save(); foreach ($items as $item) { $orderItem = new OrderItem(); $orderItem->order_id = $order->id; $orderItem->product_id = $item->product->id; $orderItem->file_id = $item->product->file->id; $orderItem->save(); CartItem::destroy($item->id); } return redirect('/order/' . $order->id); } else { return redirect('/cart'); } }
public function removeItem($id) { // deletes an item in the user basket CartItem::destroy($id); DB::table('movies')->increment('quantity', 1); return redirect('/cart'); // Add a code that readds the movie quantity for that specific item. }
public function removeItem($id) { CartItem::destroy($id); return redirect('/cart'); }
/** * Remove the specified resource from storage. * * @param CartItem $cartItem * @return \Illuminate\Http\Response */ public function destroy(CartItem $cartItem) { $cartItem->delete(); return redirect()->route('checkout.index'); }
public function nbCartItem() { return CartItem::where("product_id", $this->id)->count(); }