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 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); }