當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Comment::findOrFail方法代碼示例

本文整理匯總了PHP中app\Comment::findOrFail方法的典型用法代碼示例。如果您正苦於以下問題:PHP Comment::findOrFail方法的具體用法?PHP Comment::findOrFail怎麽用?PHP Comment::findOrFail使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Comment的用法示例。


在下文中一共展示了Comment::findOrFail方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: update

 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $comment = Comment::findOrFail($id);
     $comment->fill($request->all());
     $comment->save();
     return $comment;
 }
開發者ID:moshtaghi,項目名稱:ideabase,代碼行數:14,代碼來源:CommentController.php

示例2: show

 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $Comment = Comment::findOrFail($id);
     $Content = $Comment->entity;
     $route = route($Content->getAppointRoute('show'), $Content->id) . '#section-comment-' . $Comment->id;
     return redirect()->to($route);
 }
開發者ID:jvlstudio,項目名稱:3N1WebSite,代碼行數:13,代碼來源:CommentController.php

示例3: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $comment = Comment::findOrFail($id);
     $this->authorize('update-destroy', $comment);
     $comment->delete();
     return $comment;
 }
開發者ID:nickdunn2,項目名稱:breddit,代碼行數:13,代碼來源:CommentsController.php

示例4: update

 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['content' => 'required']);
     Comment::findOrFail($id)->update($request->only('content'));
     flash()->success(trans('forum.comment_edit'));
     return back();
 }
開發者ID:gabrieljo,項目名稱:l5essential,代碼行數:14,代碼來源:CommentsController.php

示例5: comment_delete

 public function comment_delete($id)
 {
     $comment = Comment::findOrFail($id);
     $comment->delete();
     Session::flash('comment_deleted', 'alt');
     return redirect::back();
 }
開發者ID:DarkBlackJPG,項目名稱:Learn_ON-1,代碼行數:7,代碼來源:CoursesController.php

示例6: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $comment = Comment::findOrFail($id);
     if ($comment->userId == Auth::user()->id || Auth::user()->isUserAdmin()) {
         $comment->delete();
     }
     return redirect(URL::previous());
 }
開發者ID:starkbaum,項目名稱:sucon,代碼行數:14,代碼來源:CommentsController.php

示例7: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($task_id, $comment_id)
 {
     $comment = Comment::findOrFail($comment_id);
     if ($comment->task_id != $task_id) {
         abort(404);
     }
     $comment->delete();
 }
開發者ID:BostjanOb,項目名稱:ProTODO,代碼行數:14,代碼來源:CommentsController.php

示例8: vote

 /**
  * Vote up or down for the given comment.
  *
  * @param \Illuminate\Http\Request $request
  * @param                          $id
  * @return \Illuminate\Http\JsonResponse
  */
 public function vote(Request $request, $id)
 {
     $this->validate($request, ['vote' => 'required|in:up,down']);
     $comment = Comment::findOrFail($id);
     $up = $request->input('vote') == 'up' ? true : false;
     $comment->votes()->create(['user_id' => $request->user()->id, 'up' => $up ? 1 : null, 'down' => $up ? null : 1]);
     return response()->json(['voted' => $request->input('vote'), 'value' => $comment->votes()->sum($request->input('vote'))]);
 }
開發者ID:mwasa,項目名稱:l5essential,代碼行數:15,代碼來源:CommentsController.php

示例9: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $questionId
  * @param  int  $id
  * @return Response
  */
 public function destroy($questionId, $id)
 {
     $comment = Comment::findOrFail($id);
     if (!$comment->canEdit()) {
         abort('403', 'Not authorized.');
     }
     $comment->delete();
     return redirect()->action('QuestionController@show', $questionId)->with('message', '<div class="alert alert-info">Comment deleted.</div>');
 }
開發者ID:alexpcoleman,項目名稱:fitl,代碼行數:16,代碼來源:QuestionCommentController.php

示例10: destroy

 /**
  * @param $id
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($id, Request $request)
 {
     $comment = Comment::findOrFail($id);
     if (!$request->user()->isAdmin() || $comment->user_id != $request->user()->id) {
         return redirect()->home();
     }
     $comment->delete();
     return redirect()->back()->with('success', 'Comment Deleted!');
 }
開發者ID:kinnngg,項目名稱:knightofsorrow,代碼行數:14,代碼來源:CommentController.php

示例11: update

 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $this->validate($request, ['content' => 'required']);
     $comment = Comment::findOrFail($id);
     $comment->update($request->only('content'));
     event('comments.updated', [$comment]);
     event(new ModelChanged('comments'));
     flash()->success(trans('forum.comment_edit'));
     return back();
 }
開發者ID:SH4CK3RS,項目名稱:l5essential,代碼行數:17,代碼來源:CommentsController.php

示例12: destroy

 public function destroy(Request $request, $id)
 {
     $comment = Comment::findOrFail($id);
     $comment->delete();
     $flash = ['flash_message' => 'Comment has been deleted successfully!'];
     if ($request->ajax()) {
         return response()->json($flash);
     } else {
         return redirect()->back()->with($flash);
     }
 }
開發者ID:absent1706,項目名稱:laravel-minihabr,代碼行數:11,代碼來源:CommentsController.php

示例13: handle

 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     //
     $comment = Comment::findOrFail($this->id);
     $comment->status = $this->status;
     if ($comment->save()) {
         return "success";
     } else {
         return "failed";
     }
 }
開發者ID:shine1rainbow,項目名稱:blog,代碼行數:16,代碼來源:Update.php

示例14: vote

 /**
  * Vote up or down for the given comment.
  *
  * @param \Illuminate\Http\Request $request
  * @param                          $id
  * @return \Illuminate\Http\JsonResponse
  */
 public function vote(Request $request, $id)
 {
     $this->validate($request, ['vote' => 'required|in:up,down']);
     if (Vote::whereCommentId($id)->whereUserId($request->user()->id)->exists()) {
         return response()->json(['errors' => 'Already voted!'], 409);
     }
     $comment = Comment::findOrFail($id);
     $up = $request->input('vote') == 'up' ? true : false;
     $comment->votes()->create(['user_id' => $request->user()->id, 'up' => $up ? 1 : null, 'down' => $up ? null : 1, 'voted_at' => \Carbon\Carbon::now()->toDateTimeString()]);
     return response()->json(['voted' => $request->input('vote'), 'value' => $comment->votes()->sum($request->input('vote'))]);
 }
開發者ID:appkr,項目名稱:l5essential,代碼行數:18,代碼來源:CommentsController.php

示例15: show

 /**
  * Redirects to the comment on the questions page.
  * @param  string $id The id of the comment.
  * @return Redirect
  */
 public function show($id)
 {
     $comment = Comment::findOrFail($id);
     $commentable = $comment->commentable;
     if (get_class($commentable) === 'App\\Question') {
         $questionId = $commentable->id;
     } else {
         $questionId = $commentable->question->id;
     }
     $bookmark = '#comment-' . $comment->id;
     return redirect(route('questions.show', $questionId) . $bookmark);
 }
開發者ID:nilstr,項目名稱:stackoverflow-clone,代碼行數:17,代碼來源:CommentsController.php


注:本文中的app\Comment::findOrFail方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。