public function index() { $user = \Auth::user(); $time = $this->formatDate(); $action = 'home'; $r = Signin::where('user_id', \Auth::user()->id)->first(); $count = 0; $signined = false; if ($r) { $count = $r['count']; if (substr(Carbon::now(), 0, 10) == substr($r['last_signin'], 0, 10)) { $signined = true; } } $signinList = Signin::where('last_signin', 'like', substr(Carbon::now(), 0, 10) . '%')->orderBy('last_signin', 'desc')->get(); foreach ($signinList as &$item) { $item['last_signin'] = substr($item['last_signin'], 11, 8); } $cates = Cate::orderBy('count', 'desc')->limit(6)->get(); $authors = User::orderBy('score', 'desc')->limit(6)->get(); $teams = Team::limit(3)->get(); $recommendedArticles = Article::orderBy('recommend', 'deac')->limit(4)->get(); $phpArticles = Article::where('cate_id', 1)->limit(5)->get(); $todayHotArticles = Article::where('published_at', '>=', Carbon::now()->subDay(1))->where('published_at', '<=', Carbon::now())->orderBy('view', 'deac')->limit(6)->get(); $weekHotArticles = Article::where('published_at', '>=', Carbon::now()->subDay(7))->where('published_at', '<=', Carbon::now())->orderBy('view', 'deac')->limit(6)->get(); return view('home', compact('user', 'time', 'action', 'signin', 'minus', 'count', 'signined', 'signinList', 'cates', 'authors', 'teams', 'recommendedArticles', 'phpArticles', 'todayHotArticles', 'weekHotArticles')); }
public function detailProduct($alias) { /*tim san pham*/ $product = Products::getProductByAlias($alias); //tim san pham /*lay thong tin loai san pham*/ $cateId = Cate::getIdByAlias($product->cate_alias); //$cate=alias $parentId = Cate::getParentId($cateId); $arrayCurrentCateName = Cate::getNameById($cateId); $arrayParentName = Cate::getNameById($parentId); // duong dan /*San pham cung loai*/ $productSameCate = Products::getProductsSameCate($cateId, $product->id); $lovedProductsId = ["0"]; if (Auth::check()) { $lovedProductsId = customer::LovedProduct("id"); } /* Kich thuoc quan áo thành array */ if (str_contains($product->size, ",")) { $array = explode(",", $product->size); $product->size = $array; } return view("pages.detail_products", compact("product", "arrayParentName", "arrayCurrentCateName", "productSameCate", "lovedProductsId")); }
public function welcome() { $id = 1; $parent = Cate::select('id', 'name', 'parent_id')->where('catetype_id', $id)->get()->toArray(); $article = Article::all(); return view('welcome', compact('parent', 'article')); }
public function getAdd() { $id = 1; // Catetype id =1~ Articles! $catetype = Cate_type::find($id)->first(); $parent = Cate::select('id', 'name', 'parent_id')->where('catetype_id', $id)->get()->toArray(); return view('modules.articles.add', compact('catetype', 'parent')); }
public static function getProductsOnCate($cate_id, $limit) { /*Tim danh sach con neu co*/ if ($cate_id == 1) { // loai my pham $arrayChildCateId = Cate::getSecChildId($cate_id); } else { //loai thoitrang suckhoe $arrayChildCateId = Cate::getFirstChildId($cate_id); } if (count($arrayChildCateId) > 0) { //Co con $products = Products::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"])->whereIn("cate_id", $arrayChildCateId)->orderBy("products.updated_at")->paginate($limit); } else { //Khong co con $products = Products::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"])->where("cate_id", $cate_id)->orderBy("products.updated_at")->paginate($limit); } return $products; }
public function createQuestion() { $action = 'forum'; $cates = Cate::all(); return view('member.forum.create-question', compact('action', 'cates')); }
public function DiscountGetDelete($id) { Cate::where("discount_id", $id)->update(["discount_id" => 0]); $discount = Discount::find($id); $discount->delete(); return redirect()->route("admin.discount.list"); }
public static function getCateOnDiscount($discount_id) { $cate = Cate::select(["id", "discount_id", "name"])->where("discount_id", $discount_id)->get(); return $cate; }
public function getEdit($id) { $data = Cate::findOrFail($id)->toArray(); $parent = Cate::select('id', 'name', 'parent_id')->get()->toArray(); return view('admin.cate.edit', compact('data', 'parent', 'id')); }
public function getEdit($id) { // $product = Product::findOrFail($id)->toArray(); $cate = Cate::select('*')->get()->toArray(); $product_img = Product::find($id)->pImages; return view('admin.product.edit', compact('cate', 'product', 'id', 'product_img')); }
public function postEdit(Request $request, $id) { $this->validate($request, ["txtName" => "required"], ["txtName.required" => "Please Enter Name Category"]); $cate = Cate::find($id); $cate->name = $request->txtName; $cate->alias = changeTitle($request->txtName); $cate->order = $request->txtOrder; $cate->parent_id = $request->txtParent; $cate->keywords = $request->txtKeywords; $cate->description = $request->txtDescription; $cate->save(); return redirect()->route('admin.cates.list')->with(['flash_level' => 'success', 'flash_message' => 'Success !! Complete Edit Category']); }
public function update(Requests\CreateArticleRequest $request, $id) { $article = Article::findOrFail($id); $oldCateId = $article->cate_id; $article->update($request->all()); $oldTags = Tag::where(['user_id' => \Auth::user()->id, 'article_id' => $id])->delete(); $newTags = $request->get('tags'); if ($newTags && $newTags != "多个标签以,分隔") { $newTags = str_replace(',', ',', $newTags); //中文状态逗号,替换成英文逗号 $newTags = trim($newTags, ','); $arr = explode(',', $newTags); //拆分标签入库 foreach ($arr as $k => $v) { Tag::create(array('tag' => $v, 'user_id' => \Auth::user()->id, 'article_id' => $article->id)); } } //更新分类数据 if ($oldCateId != $request->get('cate_id')) { //有分类的文章才执行原有分类自增 if ($article->cate_id > 0) { Cate::where('id', $oldCateId)->decrement('count'); Cate::where('id', $request->get('cate_id'))->increment('count'); } else { // } } return redirect('/articles'); }