public function order(Request $request) { $product = Product::where('id', $request->id)->first(); $this->data['count'] = Reviews::where('product_id', $request->id)->get(); $properti = array(); array_push($properti, $request->size); array_push($properti, $request->warna); $order = array('id' => $request->id, 'name' => $request->name, 'qty' => $request->quantity, 'price' => $request->price, 'options' => $properti); $rowid = Cart::add($order); return redirect('detail/' . $request->id)->with('success', 'Barang telah ditambahkan ke dalam keranjang '); }
/** * Delete a restaurant and all data associated with it * * @param Request $request * @return \Illuminate\Http\RedirectResponse */ public function deleteAction(Request $request) { try { $errors = array(); if (!$request->isMethod('POST')) { throw new Exception('Must be a POST request.'); } $is_ajax = $request->ajax(); $connection = DB::connection(); $connection->beginTransaction(); $restaurant_id = $request->input('id'); $restaurant = Restaurants::find($restaurant_id); if (!$restaurant) { throw new Exception('Restaurant not found'); } $bookmarks = Bookmarks::where('restaurant_id', $restaurant_id); if ($bookmarks->get()->count()) { $bookmarks->delete(); } $check_ins = CheckIns::where('restaurant_id', $restaurant_id); if ($check_ins->get()->count()) { $check_ins->delete(); } $photos = PhotosCms::where('restaurant_id', $restaurant_id); if ($photos->get()->count()) { $photos->delete(); } $restaurants_category = RestaurantsCategory::where('restaurant_id', $restaurant_id); if ($restaurants_category->get()->count()) { $restaurants_category->delete(); } $reviews = Reviews::where('restaurant_id', $restaurant_id); if ($reviews->get()->count()) { $reviews->delete(); } $restaurant->delete(); $connection->commit(); if ($is_ajax) { header('Content-Type: application/json'); $success[] = 'Restaurant ID ' . $restaurant_id . ' has been deleted'; echo json_encode(array('success' => $success)); exit; } else { $success[] = 'Restaurant ID ' . $restaurant_id . ' has been deleted'; \Session::flush('success', $success); return redirect()->back(); } } catch (Exception $e) { $connection->rollBack(); if ($is_ajax) { header('Content-Type: application/json'); $errors[] = $e->getMessage(); \Session::flush('errors', $errors); echo json_encode(array('errors' => $e->getMessage())); exit; } else { $errors[] = $e->getMessage(); \Session::flush('errors', $errors); return redirect()->back(); } } }
public function review_content(Request $request) { $this->data['review'] = Reviews::where('product_id', $request->product_id)->Paginate(5); return view('product/review_content')->with('data', $this->data); }
public function delete($id) { $product = Product::find($id); $category = Category::where('id', $product->category_id)->first(); $inOrder = OrderDetail::where('product_id', $id)->where('review', null)->get(); $reviews = Reviews::where('product_id', $id)->get(); $subcategory = Subcategory::where('id', $product->subcategory_id)->first(); if (!$product) { return redirect('master/produk/list')->with('error', 'Data tidak ada'); } else { $image = unserialize($product->image); $path = base_path() . '/storage/photo_product/'; if (count($inOrder) > 0) { $product->status = 'unactive'; if ($product->save()) { return redirect('master/produk/list')->with('success', 'Produk tidak bisa di hapus karena masih dalam order, produk sementara di non aktifkan'); } else { return redirect('master/produk/list')->with('error', '404'); } } elseif (count($inOrder) == 0) { if ($product->delete()) { foreach ($reviews as $review) { $reviews->delete(); } foreach ($inOrder as $order_product) { foreach ($order_product as $orders) { $PaymentConfirmation = PaymentConfirmation::where('order_id', $orders->id)->first(); $PaymentConfirmation->delete(); } $orders = Order::where('id', $order_product->order_id)->get(); $orders->delete(); } $total_product = $category->total_product - 1; $category->total_product = $total_product; $category->save(); $total_subcategory = $subcategory->total_product - 1; $subcategory->total_product = $total_subcategory; $subcategory->save(); if (!$image == NULL) { foreach ($image as $image) { File::delete($path . $image); } } return redirect('master/produk/list')->with('success', 'Produk ' . $product->name . ' Berhasil Dihapus'); } else { return redirect('master/produk/list')->with('error', '404'); } } } }