public static function LovedProduct($get = "all") { $arrayListId = []; $arrayProductId = []; $detailProducts = []; /*get user id*/ $customer_id = Auth::user()->id; /*get list id*/ $loveListId = LoveList::select(["id"])->where("customer_id", $customer_id)->get(); foreach ($loveListId as $id) { $arrayListId[] = $id->id; } /*get product id of list*/ if (isset($arrayListId)) { $lovedProducts = LoveListDetail::select(["product_id"])->whereIn("list_id", $arrayListId)->get(); foreach ($lovedProducts as $id) { $arrayProductId[] = $id->product_id; } } /*get product detail*/ if ($get == "all") { if (isset($arrayProductId)) { $detailProducts = Products::getProductById($arrayProductId, "array"); } return $detailProducts; } else { if ($get == "id") { return $arrayProductId; } } }
public function getProduct() { $cart = []; if (Session::has("cart")) { $temp = Session::get("cart"); $array_id = array_keys($temp); $cart = Products::getProductById($array_id, "array"); /* them field so luong*/ foreach ($cart as $key => $item) { foreach ($temp as $key2 => $item2) { if ($item->id == $key2) { $item->so_luong = $item2; } } } /******/ return $cart; } else { return $cart; } }
public function ProductGetEdit($id) { $newBillCount = count(Bill::NewBill()); $product = Products::getProductById($id); $cate = Cate::select(["id", "name"])->where("parent_id", "!=", "0")->where("parent_id", "!=", "1")->orderBy("name")->get(); return view("admin.sanpham.edit", compact("product", "cate", "newBillCount")); }