/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { //edita un post existente $post = Post::whereId($id)->firstOrFail(); $categories = Category::all(); $selectedCategories = $post->categories->lists('id')->toArray(); return view('backend.posts.edit', compact('post', 'categories', 'selectedCategories')); }
/** * 显示具体文章页面,阅读次数加1 * * @param int $id 文章id */ public function showPost($id) { $post = Post::whereId($id)->where('is_draft', '==', 0)->firstOrFail(); $post->content = EndaEditor::MarkDecode($post->content); $read = Post::whereId($id)->first()->read; $time = Post::whereId($id)->first()->updated_at; $read++; Post::whereId($id)->update(['read' => $read, 'updated_at' => $time]); return view('blog.post')->withPost($post); }
public function update($id, PostFormRequest $request) { $post = Post::whereId($id)->firstOrFail(); $post->title = $request->get('title'); $post->content = $request->get('content'); $post->slug = Str::slug($request->get('title'), '-'); $post->save(); $post->categories()->sync($request->get('categories')); return redirect(action('Admin\\PostsController@edit', $post->id))->with('status', 'The post has been updated!'); }