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 DelLovedProduct($product_id)
 {
     if (Request::ajax()) {
         if (Auth::check()) {
             $customer_id = Auth::user()->id;
             /*lay danh sach yeu thich cua customer*/
             $list_id = LoveList::select(["id"])->where("customer_id", $customer_id)->get()->toArray();
             /*bỏ yeu thich san pham */
             LoveListDetail::whereIn("list_id", $list_id)->where("product_id", $product_id)->delete();
             return json_encode(["result" => "success"]);
         } else {
             return redirect()->route("login");
         }
     } else {
         return redirect()->route("login");
     }
 }
 public function Signup(SignupRequest $request)
 {
     /*them thanh vien*/
     $firstname = $request->get("firstname");
     $lastname = $request->get("lastname");
     $pass = Hash::make($request->get("password"));
     $email = $request->get("email");
     $gender = $request->get("gender");
     $birthday = $request->get("birthday");
     $default_list_id = 0;
     $customer = customer::create(["email" => $email, "password" => $pass, "first_name" => $firstname, "last_name" => $lastname, "default_list_id" => $default_list_id, "gender" => $gender, "birthday" => $birthday]);
     /*tao danh sach mac dinh*/
     LoveList::create(["customer_id" => $customer->id, "name" => "danh sách mặc định"]);
     $default_list_id = LoveList::select(["id"])->where("customer_id", $customer->id)->first();
     /*cap nhat id danh sach mac dinh cho customer*/
     customer::where("id", $customer->id)->update(["default_list_id" => $default_list_id->id]);
     return redirect()->route("login")->with("result", "Đăng kí thành công");
 }
 public function LoveProduct()
 {
     if (Request::ajax()) {
         $customer_id = Auth::user()->id;
         $default_list_id = Auth::user()->default_list_id;
         $loveList = LoveList::select(["love_list.id", "love_list.name"])->where("love_list.customer_id", $customer_id)->get();
         /*Tao mang love list id*/
         $loveListId = [];
         foreach ($loveList as $item) {
             $loveListId[] = $item->id;
         }
         $lovedProduct = LoveListDetail::join("products", "products.id", "=", "love_list_detail.product_id")->join("cates", "products.cate_id", "=", "cates.id")->join("discounts", "discounts.id", "=", "cates.discount_id")->select(["products.*", "cates.name as cate", "cates.alias as cate_alias", "discounts.percent as percent", "love_list_detail.list_id", "love_list_detail.updated_at"])->get();
         /*dua danh sach mac dinh len top*/
         $default_list_id = Auth::user()->default_list_id;
         for ($i = 0; $i < count($loveList); $i++) {
             for ($j = $i; $j < count($loveList); $j++) {
                 if ($loveList[$j]->id == $default_list_id) {
                     $temp = $loveList[$j];
                     $loveList[$j] = $loveList[$i];
                     $loveList[$i] = $temp;
                     break;
                 } else {
                     continue;
                 }
             }
         }
         return view("pages.customerInfo.love", compact("loveList", "lovedProduct"));
     } else {
         return redirect()->route("home");
     }
 }