本文整理汇总了PHP中app\Comment::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::find方法的具体用法?PHP Comment::find怎么用?PHP Comment::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Comment
的用法示例。
在下文中一共展示了Comment::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage. Requires a post with 'comment_id' and 'position'
*
* @return Response
*/
public function store()
{
//Check user permissions
if (!Auth::user()->can('create-comment_votes')) {
abort(401, 'You do not have permission to vote on a comment');
}
//Check validation
$input = Request::all();
if (!isset($input['comment_id'])) {
abort(422, 'comment_id is required');
}
//Gets the comment that is to be voted on
$comment = Comment::find($input['comment_id']);
//Does the fields specified as fillable in the model
if (!$comment) {
abort(403, 'There is no comment with the id of ' . $input['comment_id']);
}
//Check logged in user has voted, and on this comment's motion
$vote = Vote::where('user_id', Auth::user()->id)->where('motion_id', $comment->motion_id)->first();
if (!$vote) {
abort(403, 'User must vote before posting comment');
}
$commentVote = new CommentVote($input);
$commentVote->comment_id = $comment->id;
$commentVote->vote_id = $vote->id;
if (!$commentVote->save()) {
abort(403, $commentVote->errors);
}
return $commentVote;
}
示例2: comment
public function comment(Request $request)
{
$this->validate($request, ['id' => 'required', 'type' => 'required|in:1,-1']);
$user = Auth::user();
$id = $request->input('id');
$value = $request->input('type');
$comment = Comment::find($id);
$isLiked = $comment->likedany($user->id);
if (!$isLiked) {
if ($value == 1) {
$comment->like($user->id);
$isLiked = 1;
} elseif ($value == -1) {
$comment->dislike($user->id);
$isLiked = -1;
}
} elseif ($isLiked == $value) {
$comment->unlike($user->id);
$isLiked = 0;
} elseif ($isLiked != $value) {
$comment->revertlike($user->id);
if ($isLiked == 1) {
$isLiked = -1;
} elseif ($isLiked == -1) {
$isLiked = 1;
}
}
return ['hasCallback' => 1, 'callback' => 'comment_liked', 'hasMsg' => 0, 'msg' => '', 'msgType' => '', 'returns' => ['num_like' => $comment->num_like, 'num_dislike' => $comment->num_dislike, 'is_liked' => $isLiked]];
}
示例3: getEditComment
public function getEditComment(Request $request, $id)
{
$comment = Comment::find($id);
if ($comment && $comment->comment_author_id == Auth::user()->id) {
return view('users.forms.edit_comment_form')->with('comment', $comment);
}
}
示例4: updateComment
public function updateComment(Request $request, $id)
{
$input = Request::all();
$comment = Comment::where('id', $id)->update(['content' => $input['content']]);
$comments = Comment::find($id);
return redirect(url('/form', $comments->form_id));
}
示例5: destroy
public function destroy($id)
{
$comment = Comment::find($id);
$postId = $comment->post_id;
Comment::destroy($id);
return redirect('/posts/' . $postId);
}
示例6: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
$comment = Comment::find($id);
$comment->delete();
return Redirect::to('admin/comments');
}
示例7: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$comment = Comment::find($id);
if ($comment) {
$comment->delete();
}
return Comment::all();
}
示例8: show
public function show($id)
{
$comment = Comment::find($id);
if (!$comment) {
return Response::json(['error' => ['message' => 'Comment does not exist']], 404);
}
return Response::json($comment, 200);
}
示例9: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$comment = Comment::find($id);
if ($comment->user_id == 1 || $comment->user_id == \Auth::user()->id) {
$comment->delete();
}
return $comment;
}
示例10: show
public function show($id)
{
$comment = Comment::find($id);
if (!$comment) {
return $this->error("The comment with {$id} doesn't exist", 404);
}
return $this->success($comment, 200);
}
示例11: delete_item
public function delete_item($c_id)
{
$c = Comment::find($c_id);
$this->authorize('qna-edit', $c);
$c->delete();
$redirectUrl = $this->getRedirectUrlWithComment($c);
return redirect($redirectUrl);
}
示例12: postRemove
public function postRemove($id)
{
$comment = Comment::find($id);
if ($comment->user_id == Auth::user()->id) {
$comment->delete();
}
return redirect()->back();
}
示例13: run
public function run()
{
for ($j = 1; $j <= 200; $j++) {
$user = User::find(rand(1, 10));
$comment = Comment::find($j);
Comment_like::create(['user_id' => $user->id, 'post_id' => $comment->id]);
}
}
示例14: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($kdThread)
{
//
$comment = Comment::find($kdThread);
//$threadforum=Threadforum::all();
//return view('threadforum.comment.index',compact('comment'));
return $comment->toJson();
}
示例15: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$comment = \App\Comment::find($request->id);
if ($comment->user->id == \Auth::user()->id) {
return $next($request);
} else {
return redirect('home');
}
}