where('status', $status); } if ($keyword) { $query->where('content', 'like', "%{$keyword}%"); } $paginator = $query->order('create_at', 'desc') ->paginate(['list_rows' => $limit, 'page' => $page]); $rows = []; foreach ($paginator->items() as $c) { $rows[] = [ 'id' => $c->id, 'nickname' => $c->user->nickname ?? '游客', 'article' => $c->article->title ?? '-', 'content' => $c->content, 'status' => $c->status, 'create_at' => $c->create_at, ]; } return json(['code' => 0, 'msg' => '', 'count' => $paginator->total(), 'data' => $rows]); } return View::fetch('comment/index', ['status' => $status, 'keyword' => $keyword]); } public function audit($id = 0) { $id = $id ?: (int) Request::post('id', 0); $comment = ArticleComment::find($id); if ($comment) { $comment->status = 1; $comment->save(); Article::where('id', $comment->aid)->inc('comment_count')->update(); return json(['code' => 1, 'msg' => '审核通过']); } return json(['code' => 0, 'msg' => '评论不存在']); } public function delete($id = 0) { $id = $id ?: (int) Request::post('id', 0); $comment = ArticleComment::find($id); if ($comment) { $comment->delete(); return json(['code' => 1, 'msg' => '已删除']); } return json(['code' => 0, 'msg' => '评论不存在']); } }