/** * 显示全部分类 * */ public function getArchive() { $categorys = Archive::orderBy('counts', 'desc')->get()->toarray(); $times = Post::orderBy('created_at', 'desc')->where('is_draft', '==', 0)->get()->toarray(); $j = 0; $dates = array([]); foreach ($times as $time) { $year = substr($time['created_at'], 0, 4); $month = substr($time['created_at'], 5, 2); $date = $year . $month; if ($j != 0 && $dates[$j - 1] != $date) { $dates[$j] = $date; $j++; } else { if ($j == 0) { $dates[$j] = $date; $j++; } } } return view('blog.archives')->withCategorys($categorys)->withDates($dates); }
/** * 显示文章编辑表单 * * @param int $id */ public function edit($id) { $archives = Archive::orderBy('created_at', 'desc')->get()->toArray(); $data = $this->dispatch(new PostFormFields($id)); return view('admin.post.edit')->with($data)->withArchives($archives); }