本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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();
}
示例5: comment_delete
public function comment_delete($id)
{
$comment = Comment::findOrFail($id);
$comment->delete();
Session::flash('comment_deleted', 'alt');
return redirect::back();
}
示例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());
}
示例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();
}
示例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'))]);
}
示例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>');
}
示例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!');
}
示例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();
}
示例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);
}
}
示例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";
}
}
示例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'))]);
}
示例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);
}