public function postArticle(Request $request) { $validate = \Validator::make($request->only('article_id', 'sort'), ['article_id' => 'required|numeric', 'sort' => 'required|numeric']); if ($validate->fails()) { abort(503); } $article = Article::findOrFail($request->input('article_id')); $recommend = new ArticleRecommend(); $recommend->article_id = $article->id; $recommend->sort = $request->input('sort'); $recommend->save(); return redirect()->route('admin.recommend.index'); }
/** * Execute the console command. * * @return mixed */ public function fire() { $articles = Article::all(); $xs = new \XS('inspirer'); $xsindex = $xs->index; $xsindex->clean(); foreach ($articles as $article) { $doc = new \XSDocument(); $this->output->writeln(sprintf("<comment>[Add]</comment> article [id:<info>%d</info>] - %s", $article->id, $article->title)); $doc->setFields(['id' => $article->id, 'title' => $article->title, 'name' => $article->name, 'description' => $article->description, 'keyword' => $article->keywords, 'content' => $article->content]); $xsindex->add($doc); } }
public function index(Request $request) { $articles = Article::where('category_id', '!=', 0)->where('display', '=', true)->orderBy('created_at', 'desc')->orderBy('id', 'desc')->paginate(10); $recommendDataset = ArticleRecommend::count() >= 6 ? ArticleRecommend::orderBy('sort', 'DESC')->skip(0)->take(6)->get() : []; $firstRecommend = null; $recommends = null; foreach ($recommendDataset as $recommend) { if (is_null($firstRecommend)) { $firstRecommend = $recommend->article; } else { $recommends[] = $recommend->article; } } return view('home', ['articles' => $articles, 'parse' => new Parsedown(), 'recommends' => $recommends, 'firstRecommend' => $firstRecommend]); }
public function store() { $articles = Article::all(); if (!is_dir('html')) { mkdir('html'); } $navs = Nav::orderBy('sort', 'desc')->get(); $function = function ($closure, $navs, $pid = 0) { $return = null; foreach ($navs as $nav) { if ($nav->parent_id == $pid) { if (null != ($children = call_user_func($closure, $closure, $navs, $nav->id))) { $return[] = [$nav, $children]; } else { $return[] = $nav; } } } return $return; }; $d = Option::all(); $options = []; foreach ($d as $option) { $options[$option->key] = $option->value; } view()->share('navs', $function($function, $navs)); view()->share('categories', Category::all()); view()->share('tags', Tag::all()); view()->share('options', $options); view()->share('staticMode', true); view()->share('staticCreateTime', date('Y/m/d H:i:s', time())); foreach ($articles as $article) { if (empty($article->name)) { continue; } if ($article->category_id == 0) { $data = view('page.page')->withArticle($article)->render(); } else { $data = view('page.article')->withArticle($article)->render(); } file_put_contents('html/' . $article->name . '.html', $data); } return redirect('admin/article'); }
/** * Remove the specified resource from storage. * * @param int $id * * @return Response */ public function destroy($id) { Article::findOrFail($id)->delete(); $xs = new \XS('inspirer'); $xs->index->del($id); return redirect('admin/article'); }
public function index() { $total = ['article' => Article::where('category_id', '!=', 0)->count(), 'page' => Article::where('category_id', '=', 0)->count()]; return view('admin.main')->withActive('dashboard')->with('total', $total); }
public function archive($year, $month) { // 档案不分页 $articles = Article::where(\DB::raw("DATE_FORMAT(`created_at`, '%Y %c')"), '=', "{$year} {$month}")->where('category_id', '!=', 0)->where('display', '=', true)->orderBy('created_at', 'desc')->get(); return view('page.archive')->with('articles', $articles); }