public function checkOut() { $order = new \App\Models\Order(); $order->user_id = \Auth::user()->id; $order->status = 'Pending'; $order->save(); foreach (\Cart::contents() as $item) { $order->products()->attach($item->id, ['quantity' => $item->quantity]); } \Cart::destroy(); return redirect('types/1'); }
public function postCheckout() { //Take all fields from post form $input = Input::all(); $v = Validator::make($input, Checkout::$rules); if ($v->passes()) { $checkout = Checkout::create(['user_id' => Auth::user()->id, 'email' => Input::get('email'), 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'address' => Input::get('address'), 'zip' => Input::get('zip'), 'country' => Input::get('country'), 'state' => Input::get('state'), 'phone' => Input::get('phone'), 'description' => Input::get('description')]); $order_items = Cart::contents(true); foreach ($order_items as $order) { DB::table('order_item')->insertGetId(['order_id' => $checkout->id, 'product_id' => $order['id'], 'quantity' => $order['quantity'], 'price' => $order['price'], 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); } return Redirect::to('store/index'); } return Redirect::back()->withErrors($v)->withErrors($v->getMessageBag()); }
public function postOrderGenerate(Request $request) { $orden = new \App\Models\Orden(); $orden->numero_productos = \Cart::totalItems(); $orden->total_productos = \Cart::total(); $orden->fecha = Carbon::now(); $orden->estatus = 1; $orden->cliente_id = $request->cliente_id; $orden->save(); $request->session()->put('orden_id', $orden->id); foreach (\Cart::contents() as $item) { $detalle = new \App\Models\DetalleOrden(); $detalle->producto_id = $item->id; $detalle->precio_producto = $item->price; $detalle->cantidad_producto = $item->quantity; $detalle->orden_id = $orden->id; $detalle->save(); } \Cart::destroy(); return redirect()->route('cart.confirmation'); }