当前位置: 首页>>代码示例>>PHP>>正文


PHP Post::findOrFail方法代码示例

本文整理汇总了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'));
 }
开发者ID:shawon922,项目名称:blog,代码行数:7,代码来源:PostsController.php

示例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.");
 }
开发者ID:kohrVid,项目名称:L5Beauty,代码行数:13,代码来源:PostController.php

示例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');
 }
开发者ID:andyzulu,项目名称:mini-cms,代码行数:7,代码来源:PostController.php

示例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');
 }
开发者ID:kazuhiko-hotta,项目名称:laos,代码行数:14,代码来源:PostController.php

示例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.');
 }
开发者ID:arthurolg,项目名称:blog,代码行数:13,代码来源:PostController.php

示例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');
 }
开发者ID:victorboissiere,项目名称:Synergie,代码行数:14,代码来源:PostsController.php

示例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;
 }
开发者ID:nickdunn2,项目名称:breddit,代码行数:13,代码来源:PostsController.php

示例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();
 }
开发者ID:spitzgoby,项目名称:spitzgoby,代码行数:12,代码来源:PostRequest.php

示例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);
 }
开发者ID:joaumg-deprecated,项目名称:joaumg_com,代码行数:12,代码来源:RelationshipsTest.php

示例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);
 }
开发者ID:productionEA,项目名称:pockeyt-api,代码行数:7,代码来源:PostsController.php

示例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);
     }
 }
开发者ID:mario650mm,项目名称:Permisos,代码行数:13,代码来源:PostsController.php

示例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');
 }
开发者ID:nickfranciosi,项目名称:nickfranciosi.com,代码行数:15,代码来源:PostController.php

示例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'));
 }
开发者ID:rogercbe,项目名称:acl_roles,代码行数:8,代码来源:PostController.php

示例14: handleDelete

 public function handleDelete()
 {
     // Handle the delete confirmation.
     $id = \Input::get('post');
     $post = Post::findOrFail($id);
     $post->delete();
     return \Redirect::action('PostsController@index');
 }
开发者ID:MartinRowe,项目名称:blog,代码行数:8,代码来源:PostsController.php

示例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'));
 }
开发者ID:celine24,项目名称:Back,代码行数:12,代码来源:BlogController.php


注:本文中的app\Post::findOrFail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。