本文整理汇总了PHP中app\Post::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::findOrFail方法的具体用法?PHP Post::findOrFail怎么用?PHP Post::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
public function show($id)
{
$post = Post::findOrFail($id);
//dd($post->created_at->diffForHumans());
//dd($post->published_at);
return view('posts.show', compact('post'));
}
示例2: destroy
/**
* 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.");
}
示例3: update
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');
}
示例4: update
/**
* 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');
}
示例5: destroy
/**
* 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.');
}
示例6: update
/**
* 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');
}
示例7: destroy
/**
* 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;
}
示例8: authorize
/**
* 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();
}
示例9: testPostDificultyLevelRelationship
/**
* 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);
}
示例10: destroy
public function destroy(DeletePostRequest $request, $id)
{
$post = Post::findOrFail($id);
$profile_path = profile_path($post->profile);
$post->delete();
return redirect()->to($profile_path);
}
示例11: update
/**
* Update the given post.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$post = Post::findOrFail($id);
if (Gate::denies('update', $post)) {
abort(403);
}
}
示例12: update
/**
* 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');
}
示例13: edit
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'));
}
示例14: handleDelete
public function handleDelete()
{
// Handle the delete confirmation.
$id = \Input::get('post');
$post = Post::findOrFail($id);
$post->delete();
return \Redirect::action('PostsController@index');
}
示例15: article
/**
* @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'));
}