public function delete()
 {
     $product = product::where('categoryID', Input::get('id'))->get();
     if (count($product) > 0) {
         if (Input::exists('json')) {
             return json_encode(array('result' => -1, 'message' => 'Loại sản phẩm "' . Input::get('title') . '" đã có sản phẩm. Không thể xóa'));
         }
         return Redirect::to('admin/category')->with(['message' => 'Loại sản phẩm "' . Input::get('title') . '" đã có sản phẩm. Không thể xóa']);
     }
     $category = category::find(Input::get('id'));
     if ($category->delete()) {
         if (Input::exists('json')) {
             return json_encode(array('result' => 1));
         }
         return Redirect::to('admin/category')->with(['message' => 'Xóa thành công loại sản phẩm "' . Input::get('title') . '"']);
     } else {
         if (Input::exists('json')) {
             return json_encode(array('result' => -1, 'message' => 'Có lỗi. Xóa thất bại'));
         }
         return Redirect::to('admin/category')->with(['message' => 'Loại sản phẩm "' . Input::get('title') . '" đã có sản phẩm. Không thể xóa']);
     }
 }
 public function postFinish()
 {
     $order = order::find(Input::get('id'));
     $order->status = 1;
     if ($order->update()) {
         $finish = new finishorder();
         $data = array('name' => Input::get('name'), 'idorder' => Input::get('id'));
         $finish->fill($data);
         if ($finish->save()) {
             $detailorder = detailorder::select('productID', 'quantity')->where('orderid', Input::get('id'))->get();
             foreach ($detailorder as $value) {
                 $producto = product::find($value->productID);
                 $producto->quantity = $producto->quantity - $value->quantity;
                 $producto->update();
             }
             return 1;
         }
         $order->status = 0;
         $order->update();
         return -1;
     }
     return -1;
 }
 public static function getproductMaxView()
 {
     return product::where("display", "=", 1)->where("bin", "=", 0)->orderBy('view', 'desc')->take(5)->get();
 }
 public function deletemenu()
 {
     if (Session::get('logininfo')->level == 3) {
         return view('admin.error');
     }
     if (Input::get("root") === "0") {
         $menu = menu::where('root', Input::get('id'))->get();
         if (count($menu) > 0) {
             if (Input::exists('json')) {
                 return json_encode(array('result' => -1, 'message' => 'Menu "' . Input::get('title') . '" đã có menu con. Không thể xóa'));
             }
         }
     }
     if (Input::get("url2") == "") {
         $product = product::where('menuID', Input::get('id'))->get();
         if (count($product) > 0) {
             if (Input::exists('json')) {
                 return json_encode(array('result' => -1, 'message' => 'Menu "' . Input::get('title') . '" đã có sản phẩm. Không thể xóa'));
             }
         }
     }
     $menu = menu::find(Input::get('id'));
     if ($menu->delete()) {
         if (Input::exists('json')) {
             return json_encode(array('result' => 1));
         }
     } else {
         if (Input::exists('json')) {
             return json_encode(array('result' => -1, 'message' => 'Có lỗi. Xóa thất bại'));
         }
     }
 }
 public function postDelete()
 {
     if (Session::get('logininfo')->level != 1) {
         return view('admin.error');
     }
     $product = product::where('user', Input::get('id'))->get();
     if (count($product) > 0) {
         if (Input::exists('json')) {
             return json_encode(array('result' => -1, 'message' => 'QTV "' . Input::get('title') . '" đã đăng sản phẩm. Không thể xóa'));
         }
         return redirect('admin/ad')->with(['message' => 'QTV "' . Input::get('title') . '" đã đăng sản phẩm. Không thể xóa']);
     }
     $news = news::where('user', Input::get('id'))->get();
     if (count($news) > 0) {
         if (Input::exists('json')) {
             return json_encode(array('result' => -1, 'message' => 'QTV "' . Input::get('title') . '" đã đăng tin tức. Không thể xóa'));
         }
         return redirect('admin/ad')->with(['message' => 'QTV "' . Input::get('title') . '" đã đăng tin tức. Không thể xóa']);
     }
     $admin = admin::find(Input::get('id'));
     if ($admin->delete()) {
         if (Input::exists('json')) {
             return json_encode(array('result' => 1));
         }
         return redirect('admin/ad')->with(['message' => 'Xóa thành công QTV "' . Input::get('title') . '"']);
     } else {
         if (Input::exists('json')) {
             return json_encode(array('result' => -1, 'message' => 'Có lỗi. Xóa thất bại'));
         }
         return redirect('admin/ad')->with(['message' => 'QTV "' . Input::get('title') . '" đã có sản phẩm. Không thể xóa']);
     }
 }
 public function delete()
 {
     $order = detailorder::where('productID', Input::get('id'))->get();
     if (count($order) > 0) {
         return Redirect::to('admin/product/recyclebin')->with(['message' => 'Sản phẩm "' . Input::get('title') . '" đã có đơn đặt hàng. Bạn không thể xóa.']);
     }
     $product = product::find(Input::get('id'));
     if ($product->delete()) {
         DB::table('detailproduct')->where('productID', Input::get('id'))->delete();
         return Redirect::to('admin/product/recyclebin')->with(['message' => 'Xóa thành công sản phẩm "' . Input::get('title') . '"']);
     } else {
         return Redirect::to('admin/product/recyclebin')->with(['message' => 'Có lỗi xóa sản phẩm "' . Input::get('title') . '" thất bại. Vui lòng thử lại.']);
     }
 }