예제 #1
0
 /**
  * Show article.
  *
  * @param  int $idFormFacade
  * @return mixed
  */
 public function getArticle($id)
 {
     try {
         $post = Article::with('user', 'category')->whereId(intval($id))->orWhere('slug', $id)->firstOrFail();
         $view = config('admin.views.post');
         return view($view, compact('post'));
     } catch (ModelNotFoundException $e) {
         abort(404);
     }
     return false;
 }
예제 #2
0
 public function timeline($category = NULL, $options)
 {
     $model = Article::getInstance()->timeline($category, $options);
     $model = $model->isEmpty() ? [] : $model;
     $result = $this->parseMaxpage($model);
     foreach ($model as $item) {
         $item = $this->format($item);
         $item = $this->formatNumber($item);
         $result[] = $item;
     }
     return $result;
 }
예제 #3
0
 /**
  * 文章列表页面
  * @param $category
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
  */
 public function getList($category)
 {
     $category = Category::getInstance()->findByName($category);
     if (empty($category)) {
         return redirect('/site/index');
     }
     $articles = Article::getInstance()->findByCategory($category->id);
     $this->viewData('crumbs', $this->articleCrumbs($category));
     $this->viewData('summary', $this->articleSummary($category));
     $this->viewData('articles', $this->articleList($articles));
     $this->viewData('bodyId', 'article-container');
     $this->viewData('navMenuActive', 'article-detail');
     return view('frontend.article.category', $this->viewData);
 }
예제 #4
0
 public function categorySummary($category)
 {
     $query = Article::selectRaw('category_id, count(article.id) as total, category.name')->leftJoin('category', 'category.id', '=', 'article.category_id')->groupBy('article.category_id')->whereRaw('category.pid=0');
     $model = $query->get();
     $result = [];
     foreach ($model as $item) {
         $temp = ['id' => $item->category_id, 'total' => $item->total, 'name' => $item->name];
         if ($category == $item->category_id) {
             $temp['active'] = true;
         }
         $result[] = $temp;
     }
     return $result;
 }
예제 #5
0
 private function saveArticle($title, $category, $file)
 {
     $time = time();
     $title = explode('.', $title);
     if (!isset($title[1])) {
         $slug = str_replace([' ', '-'], '_', $title[0]);
     } else {
         $slug = $title[1];
     }
     $title = $title[0];
     $content = file_get_contents($file);
     $slug = "{$category}_{$slug}";
     $model = Article::withTrashed()->whereRaw("slug=?", [$slug])->first();
     if ($model) {
         $model->body = $content;
     } else {
         $model = new Article();
         $category_id = $this->parseCategory($category);
         $model->title = $title;
         $model->slug = $slug;
         $model->body = $content;
         $model->category_id = $category_id;
         $model->user_id = 1;
         $model->author = 'straysh';
         $model->published_at = $time;
     }
     if (!$model->save()) {
         var_dump($model->toArray());
         exit(-1);
     }
 }