/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $post = Post::findOrFail($id); $post->tags()->detach(); $post->delete(); return redirect()->route('admin.post.index')->withSuccess('Post deleted.'); }
public function update(Request $request, $id) { $post = Post::findOrFail($id); $this->validate($request, ['title' => 'required', 'content' => 'required', 'author' => 'required']); $input = $request->all(); $post->fill($input)->save(); return redirect()->route('posts.index'); }
public function show($id) { $post = Post::findOrFail($id); // if($post==null){ // abort('404'); // } return view('post.post')->with('post', $post); }
/** * Return the field values from the model * * @param integer $id * @param array $fields * @return array */ protected function fieldsFromModel($id, array $fields) { $post = Post::findOrFail($id); $fieldNames = array_keys(array_except($fields, ['tags'])); $fields = ['id' => $id]; foreach ($fieldNames as $field) { $fields[$field] = $post->{$field}; } $fields['tags'] = $post->tags()->lists('tag')->all(); return $fields; }
public function destroyPost($id) { try { $post = Post::findOrFail($id); $post->tags()->detach(); $oldImage = public_path() . config('model.posts.path_folder_photo_post') . $post->images; if (File::exists($oldImage)) { File::delete($oldImage); } $post->delete(); } catch (Exception $e) { throw new Exception("Error Processing Request", 1); } }
public function editPost() { $postValue = \Input::get('Post'); if (is_null($postValue)) { $postValue = \Input::get('id'); $post = Post::findOrFail($postValue); if ($post->user_id != \Auth::user()->id) { return abort(403, 'Unauthorized'); } return view('home.editPost', compact('post')); } else { $post = Post::findOrFail($postValue['id']); $post->fill($postValue); $post->save(); return redirect(route('home')); } }
/** * Show a post * @param integer $id id of a post * @return Respos */ public function show($id) { try { DB::beginTransaction(); $post = Post::findOrFail($id); $nview = $post->nview; if (is_string($nview)) { $nview = (int) $nview; } $nview++; $post->nview = $nview; $post->save(); DB::commit(); //Related post $relatedPost = Post::where('id', '!=', $id)->where('is_active', 1)->orderBy('created_at', 'desc')->take(5)->get(); $url = config('media.url'); return view('website.show', compact('post', 'relatedPost', 'url')); } catch (ModelNotFoundException $e) { DB::rollback(); $message = "Không tồn tại bài viết hoặc bài viết chưa active."; $alertClass = "alert-danger"; return redirect()->back()->with(compact('message', 'alertClass')); } }
/** * Remove the specified resource from storage. * * @param int $idx * @return Response */ public function destroy($idx) { $this->checkParametersEmpty(); $comment = Post::findOrFail($idx); $comment->delete(); return $this->getCodeResponse(Response::HTTP_NO_CONTENT); }
/** * Destroy a post if it exists. * * @param $id * @return Response */ public function destroy($id) { $post = Post::findOrFail($id); $post::destroy($id); // Delete comments whos post_id matches the current post that is being deleted Comment::where('post_id', '=', $id)->delete(); return redirect()->action('PostController@index'); }
/** * Returns one post by id * @param int $id * @return Post */ public function find($id) { return Post::findOrFail($id); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $post = Post::findOrFail($id); return view('frontend.post.show', compact('post')); }
/** * Switch status seen of a post */ public function seenPost($idPost) { if (Request::ajax()) { DB::beginTransaction(); try { $post = Post::findOrFail($idPost); $post->seen = $post->seen ? 0 : 1; $post->save(); } catch (ModelNotFoundException $e) { DB::rollback(); return response()->json(['error' => true]); } DB::commit(); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $comment = Post::findOrFail($id); $comment->delete(); return $this->getCodeResponse(Response::HTTP_NO_CONTENT); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $post = Post::findOrFail($id); return view('site.blog.show')->with('post', $post); }