public function Login(LoginRequest $request) { $value = ["email" => $request->get("email"), "password" => $request->get("password")]; if ($request->remember_me == "1") { $remember = true; } else { $remember = false; } if ($this->auth->attempt($value, $remember)) { if ($request->get("email") == "*****@*****.**") { //admin return redirect()->route("admin.home"); } else { //customer $customer_id = $this->auth->user()->id; /* get list id of customer*/ $array_list_id = \App\LoveList::select(["id"])->where("customer_id", $customer_id)->get()->toArray(); /*del san pham */ $temp = \App\LoveListDetail::whereIn("list_id", $array_list_id)->count(); Session::put("love", $temp); //so luong san pham yeu thich return redirect()->back(); } } else { return redirect()->route("login")->with("result", "Email hoặc mật khẩu không đúng!"); } }
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 MoveLovedProduct($product, $from, $to) { if (Request::ajax()) { if (Auth::check()) { LoveListDetail::where("list_id", $from)->where("product_id", $product)->update(["list_id" => $to]); return json_encode(["result" => "success"]); } else { return redirect()->route("login"); } } else { return redirect()->route("login"); } }
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"); } }