/** * Run the database seeds. * * @return void */ public function run() { // 从数据库中获取的ArticleTag集合 $tags = \App\Model\Tag::all(); // 初始化博客的路径 $dir = "/root/blog"; $file_system = new Filesystem(); $files = $file_system->allFiles($dir); foreach ($files as $file) { $file_extension = $file_system->extension($file); if ($file_extension != 'md') { continue; } $create_time_stamp = $file_system->lastModified($file); $create_time = gmdate("Y-m-d", $create_time_stamp); $file_content = $file_system->get($file); $file_name = preg_replace('/^.+[\\\\\\/]/', '', $file); $file_name = explode(".md", $file_name); $blog_name = $file_name[0]; $last_dir = dirname($file); $current_tag_name = preg_replace('/^.+[\\\\\\/]/', '', $last_dir); $article_type_id = 0; foreach ($tags as $tag) { $tag_name = $tag->name; if (strcmp($current_tag_name, $tag_name) == 0) { $article_type_id = $tag->id; break; } } $article_id = \App\Model\Article::create(['cate_id' => $article_type_id, 'user_id' => 1, 'title' => $blog_name, 'content' => $file_content, 'tags' => $article_type_id, 'created_at' => $create_time, 'updated_at' => $create_time])->id; \App\Model\ArticleStatus::create(['art_id' => $article_id, 'view_number' => 0]); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit(Tag $tag) { return View::make($this->getView('edit'))->with("thisTag", $tag)->withTags(Tag::all()); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(ArticleRequest $request, Article $article) { if ($article = $this->updateArticle($request, $article)) { Flash::success('修改成功!'); return View::make($this->getView('edit'))->withArticle($article)->withTags(Tag::all()); } else { Flash::error('修改失败!'); return Redirect::back()->withInput(); } }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { // $tags = Tag::all(); return view('admin.tag.index')->withTags($tags); }