當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。