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


PHP Post::findOrFail方法代码示例

本文整理汇总了PHP中app\models\Post::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::findOrFail方法的具体用法?PHP Post::findOrFail怎么用?PHP Post::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Post的用法示例。


在下文中一共展示了Post::findOrFail方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: destroy

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

示例2: update

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

示例3: show

 public function show($id)
 {
     $post = Post::findOrFail($id);
     //        if($post==null){
     //            abort('404');
     //        }
     return view('post.post')->with('post', $post);
 }
开发者ID:popohum,项目名称:Earths-Best,代码行数:8,代码来源:PostController.php

示例4: fieldsFromModel

 /**
  * 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;
 }
开发者ID:saviorZSC,项目名称:zsc_laravel,代码行数:18,代码来源:PostFormFields.php

示例5: destroyPost

 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);
     }
 }
开发者ID:doankhoi,项目名称:Application,代码行数:14,代码来源:PostRepository.php

示例6: editPost

 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'));
     }
 }
开发者ID:juliardi,项目名称:jualjasa,代码行数:17,代码来源:HomeController.php

示例7: show

 /**
  * 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'));
     }
 }
开发者ID:doankhoi,项目名称:Application,代码行数:29,代码来源:WebsiteController.php

示例8: destroy

 /**
  * 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);
 }
开发者ID:guduchango,项目名称:limoncello,代码行数:13,代码来源:PostsController.php

示例9: destroy

 /**
  * 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');
 }
开发者ID:sgelbart,项目名称:Laravel,代码行数:14,代码来源:PostController.php

示例10: find

 /**
  * Returns one post by id
  * @param int $id 
  * @return Post
  */
 public function find($id)
 {
     return Post::findOrFail($id);
 }
开发者ID:elieandraos,项目名称:gaia-posts,代码行数:9,代码来源:PostRepository.php

示例11: show

 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $post = Post::findOrFail($id);
     return view('frontend.post.show', compact('post'));
 }
开发者ID:mrcoco,项目名称:base,代码行数:11,代码来源:PostController.php

示例12: seenPost

 /**
  * 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();
     }
 }
开发者ID:doankhoi,项目名称:Application,代码行数:18,代码来源:PostController.php

示例13: destroy

 /**
  * 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);
 }
开发者ID:jonpitch,项目名称:limoncello-collins,代码行数:12,代码来源:PostsController.php

示例14: show

 /**
  * 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);
 }
开发者ID:jclyons52,项目名称:mycourse-rocks,代码行数:11,代码来源:BlogController.php


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