public function show($id) { $post = Post::findOrFail($id); //dd($post->created_at->diffForHumans()); //dd($post->published_at); return view('posts.show', compact('post')); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $post = Post::findOrFail($id); $post->tags()->detach(); $post->delete(); return redirect()->routes("admin.post.index")->withSuccess("Post deleted."); }
public function update(Request $request, $slug) { $this->validate($request, ['title' => 'required | unique:posts,title,' . $request->id, 'slug' => 'required | unique:posts,slug,' . $request->id, 'content' => 'required']); $post = Post::findOrFail($request->id); $post->update(['title' => $request->get('title'), 'content' => $request->get('content'), 'description' => $request->get('description'), 'slug' => $request->get('slug')]); return redirect('admin/posts'); }
/** * Update the specified resource in storage. * * @param int $id * * @return Response */ public function update($id, Request $request) { $post = Post::findOrFail($id); $post->update($request->all()); Session::flash('flash_message', 'Post updated!'); return redirect('post'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $post = Post::findOrFail($id); $post->tags()->detach(); $post->delete(); return redirect()->route('admin.post.index')->withSuccess('Artículo borrado.'); }
/** * Show form to update post with right data * * @param PostRequest|Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(PostRequest $request, $id) { $post = Post::findOrFail($id); $post->update($request->all()); flash('Post modified with success'); return redirect()->route('admin-posts.index'); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $post = Post::findOrFail($id); $this->authorize('update-destroy', $post); $post->delete(); return $post; }
/** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { if ($this->isUpdate()) { return Post::findOrFail($this->get('id'))->user_id == \Auth::id(); } return \Auth::check(); }
public function show($id) { $post = Post::findOrFail($id); // $user = Auth::user()->name; // $usr = Auth::user(); return view('posts.show', compact('post')); }
/** * Test Post -> Dificulty Level relationship * * @return void */ public function testPostDificultyLevelRelationship() { $this->assertTrue(Post::findOrFail(1) instanceof Post); $relationshipCollection = Post::find(1)->dificulty()->get(); $collection = collect([]); $this->assertTrue($relationshipCollection instanceof $collection); }
public function destroy(DeletePostRequest $request, $id) { $post = Post::findOrFail($id); $profile_path = profile_path($post->profile); $post->delete(); return redirect()->to($profile_path); }
/** * Update the given post. * * @param int $id * @return Response */ public function update($id) { $post = Post::findOrFail($id); if (Gate::denies('update', $post)) { abort(403); } }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { $post = Post::findOrFail($id); $post->update($request->all()); $tags = $request->input('tag_list') ? $request->input('tag_list') : []; $post->tags()->sync($this->syncUpTags($tags)); return redirect('/blog'); }
public function edit($id) { $post = Post::findOrFail($id); if (Gate::denies('edit_forum') or !$this->user->owns($post)) { abort(403, 'Sorry not sorry'); } return view('posts.edit', compact('post')); }
public function handleDelete() { // Handle the delete confirmation. $id = \Input::get('post'); $post = Post::findOrFail($id); $post->delete(); return \Redirect::action('PostsController@index'); }
/** * @param $id * @return \Illuminate\View\View */ public function article($id) { $post = Post::findOrFail($id); $userPosts = Post::published()->orderByRaw('RAND()')->where('user_id', $post->user->id)->where('id', '!=', $post->id)->orderBy('created_at', 'desc')->take(3)->get(); $jobPosts = Post::published()->orderByRaw('RAND()')->where('job_id', $post->job->id)->where('id', '!=', $post->id)->get()->take(2); $postSticky = Post::published()->orderByRaw('RAND()')->where('is_sticky', 'on')->where('id', '!=', $post->id)->take(1)->get(); return view('pages.blog.article', compact('post', 'userPosts', 'jobPosts', 'postSticky')); }
public function editPost($id, EditPostRequest $request) { $post = Post::findOrFail($id); $post->update(['post' => $request->input('post'), 'editor_id' => \Auth::id(), 'editor_name' => \Auth::user()->name, 'was_edited' => 1, 'edit_reason' => $request->input('edit_reason')]); Notification::create(['not_title' => 'Kliknij i przejdź do posta, aby sprawdzić szczegóły', 'not_body' => 'Twój post w artykule został edytowany', 'not_status' => 5, 'not_from_user_name' => \Auth::user()->name, 'user_id' => $post->user['id'], 'not_route' => '' . $request->input('take_uri') . '#post' . $id . '']); flash()->success('Udało Ci się edytować post o ID <b>' . $id . '</b>!'); return redirect('/admin/article/' . $request->input('take_article_id') . ''); }
public function show($id) { $post = Post::findOrFail($id); if (Gate::denies('show-post', $post)) { abort(403, 'Sorry, denied'); } return $post->title; }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $post = Post::findOrFail($id); $articles = Post::published()->get(); $user = Auth::user(); $post->load('user', 'comments'); return view('posts.post', compact('post', 'articles', 'user')); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $post = Post::findOrFail($id); if (Gate::denies('update', $post)) { abort(403, 'no f*****g way bitch'); } return $post->title; }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, Request $request) { $post = Post::findOrFail($id); if ($request->has('publication')) { $post->published = $request->get('publication'); $post->save(); } return redirect(route('admin.posts.index')); }
public function show($id) { $post = Post::findOrFail($id); // dd(Gate::denies('edit_post', $post)); if (Gate::denies('edit_post', $post)) { return 'Khong duoc roi ban oi'; } return $post->title; }
public function edit($id) { $post = Post::findOrFail($id); if (Gate::denies('update', $post)) { Alert::danger('No tienes permisos para editar este post'); return redirect('posts'); } return $post->title; }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { try { $post = Post::findOrFail($id); echo $post; } catch (ModelNotFoundException $e) { return Response::json(['error' => 'The specified resource does not exist.'], HttpResponse::HTTP_NOT_FOUND); } }
protected function fieldsFromModel($id, array $fields) { $post = Post::findOrFail($id); $fieldNames = array_keys($fields); $fields = ['id' => $id]; foreach ($fieldNames as $field) { $fields[$field] = $post->{$field}; } return $fields; }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $this->data['post'] = App\Post::findOrFail($id); $this->data['thread'] = App\Thread::findOrFail($this->data['post']->thread_id); if (!\Auth::hasPerm($this->data['post']->user_id)) { \Session::flash('flash_message', 'You do not have permission to edit this post.'); return redirect('thread/' . $this->data['post']->thread_id); } return view('forum.posts.edit', $this->data); }
/** * Return the field values from the model * @param integer $id Post ID * @param array $fields postModelFieldList * @return array $fieldsList */ public 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()->pluck('tag')->all(); return $fields; }
public function destroy($postId) { try { $post = Post::findOrFail($postId); $post->delete(); } catch (Exception $e) { Session::flash('message', 'Fail : ' . $e->getMessage()); return Redirect::back(); } return Redirect::to(route('admin.post.index')); }
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; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ($this->auth->check()) { $id = $request->route()->getParameter('posts'); $post = \App\Post::findOrFail($id); $user = $this->auth->user(); if ($post->user_id != $user->id) { return redirect()->route('posts.index')->with('status', 'No Access.'); } } return $next($request); }