public function beforeRender() { $this->template->articles = $this->article->where('menu IS NOT NULL'); $this->template->DPH = self::DPH; // Sets information for facebook $this->template->og = array(); }
public function renderDefault() { $currentDate = date('Y-m-d H:i:s'); // povolene akce s aktualnim datem platnosti serazene od nejnovejsi $this->template->sales = $this->sale->where("enable != 0 AND ((start IS NULL AND end IS NULL) OR (start < '{$currentDate}' AND end > '{$currentDate}') OR (start IS NULL AND end > '{$currentDate}') OR (start < '{$currentDate}' AND end IS NULL))")->order('created DESC'); $this->template->goodsRecommended = $this->goods->where('recommended != 0')->order('id DESC')->limit(6); $this->template->text = ""; foreach ($this->article->where(['menu' => self::SALE_PAGE_MENU])->limit(1) as $a) { if (strip_tags($a->text)) { $this->template->text = $a->text; } } }
public function show($id = 0) { if (!preg_match("/^[1-9]\\d*\$/", $id)) { return Redirect::to('/'); } $type = Category::find($id); if (empty($type)) { return Redirect::to('/'); } $keywords = $type->keywords; $description = $type->description; $subs = $type->subs()->get(); if (count($subs) > 0) { $templet = 'sub'; if ($type->templet_all != '') { $templet = $type->templet_all; } return Theme::view('category.' . $templet, compact('type', 'subs', 'keywords', 'description')); } else { $templet = 'show'; if ($type->templet_nosub != '') { $templet = $type->templet_nosub; } $articles = Article::where('category_id', $id)->sortByDesc('id')->paginate(20); return Theme::view('category.' . $templet, compact('type', 'articles', 'keywords', 'description')); } }
public function about(Request $request) { $id = $request->input('id'); $about = Article::find($id); $aboutList = Article::where('cate_id', 3)->orderBy('priority', 'asc')->paginate(20); return view('themes.default.about', ['about' => $about, "aboutList" => $aboutList, 'id' => $id]); }
public function getType($id) { $id = intval($id); $articles = Article::where('category_id', $id)->sortByDesc('id')->paginate(20); $categories = Category::where('is_nav_show', '>', '0')->sortByDesc('id')->get(); $type = Category::find($id); return Theme::view('admin.articles.index', compact(['articles', 'categories', 'type'])); }
public function index() { $lastArticleUpdatetime = Carbon::now(); $articles = Article::where('published_at', '<=', Carbon::now())->orderBy('updated_at', 'desc')->limit(config('blog.articles_per_page'))->get(); if (count($articles) == config('blog.articles_per_page')) { $lastArticleUpdatetime = $articles[config('blog.articles_per_page') - 1]->updated_at; } return view('blog.index', ['articles' => $articles, 'lastArticleUpdatetime' => $lastArticleUpdatetime]); }
/** * Display a listing of the resource. * * @return Response */ public function index(Request $request) { $catId = $request->input('cateId'); if (empty($catId)) { $catId = 1; } $articleList = Article::where("cate_id", $catId)->orderBy('id', 'DESC')->paginate(10); viewInit(); return homeView('articlelist', array('articleList' => $articleList, 'cateId' => $catId)); }
public function show($id) { if (!preg_match("/^[1-9]\\d*\$/", $id)) { return Redirect::to('/'); } $type = Category::find($id); if (!$type) { return Redirect::to(route('admin.articles.index')); } $articles = Article::where('category_id', $id)->sortByDesc('id')->paginate(20); return Theme::view('admin.articles.show', compact('articles', 'type')); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(ArticleForm $result, $id) { // try { $data = array('title' => $result->input('title'), 'user_id' => 9, 'cate_id' => $result->input('cate_id'), 'content' => $result->input('content'), 'tags' => $result->input('tags')); if (Article::isHasFile('pic')) { $data['pic'] = Article::uploadImg('pic'); } if (Article::where('id', $id)->update($data)) { Notification::success('更新成功'); // 清除缓存 Cache::tags(Article::REDIS_ARTICLE_PAGE_TAG)->flush(); Cache::forget(Article::REDIS_ARTICLE_CACHE . $id); return redirect()->route('backend.article.index'); } } catch (\Exception $e) { return redirect()->back()->withErrors(array('error' => $e->getMessage()))->withInput(); } }
public static function article_data($num, $order = null, $where = null, $type = 0, $offset = 0) { $num = intval($num); $offset = intval($offset); $key = 'article_' . $num . '_' . $order . '_' . $where . '_' . $type . '_' . $offset; if (Cache::store('article')->has($key)) { $date = Cache::store('article')->get($key); return $date; } else { switch ($order) { case byId: $order_str = 'id'; break; case bySort: $order_str = 'sort'; break; case byViews: $order_str = 'views'; break; default: $order_str = 'id'; break; } $type = intval($type); switch ($where) { case findAll: $date = Article::sortByDesc($order_str)->take($num)->Offset($offset)->get(); break; case findRecommend: $date = Article::where('is_recommend', '>', 0)->sortByDesc($order_str)->take($num)->Offset($offset)->get(); break; case findCategory: $date = Article::where('category_id', $type)->orderBy($order_str, 'desc')->take($num)->Offset($offset)->get(); break; default: $date = Article::sortByDesc($order_str)->take($num)->Offset($offset)->get(); break; } $expiresAt = Carbon::now()->addMinutes(60); //设置缓存时间 Cache::store('article')->put($key, $date, $expiresAt); return $date; } }
public function delete() { $id = Input::get('id'); $validator = Validator::make(array('id' => $id), array('id' => 'required|integer|exists:articles,id')); if ($validator->fails()) { return response()->json(['data' => false, 'msg' => json_encode($validator->messages())]); } try { Article::where('id', $id)->delete(); //Todo::delete other about this article!!! } catch (\Exception $e) { return response()->json(['data' => false, 'msg' => json_encode($e->getMessage())]); } return response()->json(['data' => true, 'msg' => '成功删除文章!']); }
public function loadMoreArticle(Request $request) { $lastArtilceUpdateTime = $request->input('lastArticleUpdateTime'); $articles = Article::where('published_at', '<=', Carbon::now())->where('updated_at', '<', $lastArtilceUpdateTime)->orderBy('updated_at', 'desc')->limit(config('blog.articles_per_page'))->get(); return response()->json(array('articles' => $articles)); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(ArticleForm $result, $id) { // try { if (Article::where('id', $id)->update(Article::setFieldData())) { Notification::success('更新成功'); return Redirect::route('backend.article.index'); } } catch (\Exception $e) { return Redirect::back()->withErrors(array('error' => $e->getMessage()))->withInput(); } }