public function article(Request $request, Article $article) { $user = Auth::user(); $comment = $article->comments()->create(['user_id' => $user->id, 'body' => $request->input('body')]); $article->update(['num_comment' => $article->comments()->count()]); $this->stream($comment); Flash::success(trans('message.articleCommentAdded')); return redirect()->back(); }
/** * Include comments. * * @param \App\Article $article * @param \League\Fractal\ParamBag|null $params * @return \League\Fractal\Resource\Collection * @throws \Exception */ public function includeComments(Article $article, ParamBag $params = null) { $transformer = new \App\Transformers\CommentTransformer($params); $parsed = $this->getParsedParams(); $comments = $article->comments()->limit($parsed['limit'])->offset($parsed['offset'])->orderBy($parsed['sort'], $parsed['order'])->get(); return $this->collection($comments, $transformer); }
/** * Stubbing test data. * * @param array $overrides */ protected function createTestStub($overrides = []) { $this->user = !empty($overrides) ? factory(User::class)->create() : factory(User::class)->create($overrides); $this->user->attachRole(Role::find(2)); $this->article = factory(Article::class)->create(['title' => 'title', 'author_id' => $this->user->id, 'content' => 'description']); $this->article->comments()->save(factory(Comment::class)->make(['author_id' => $this->user->id])); $this->article->tags()->attach(1); $this->article->attachments()->save(factory(Attachment::class)->make()); }
/** * Created By Dara on 8/2/2016 * add reply to comment */ public function article(Article $article, $comment_id, Request $request) { $user = $this->user; $this->validate($request, ['content' => 'required']); if ($comment_id) { //check if the comment has been set or not (reply) level 2 comment $comment = Comment::findOrFail($comment_id); $parent_id = $comment->id; $msg = trans('users.answerSent'); $nested = true; } else { //level 1 comment $parent_id = 0; $msg = trans('users.commentSent'); $nested = false; } //add comment to db $newComment = $article->comments()->create(['user_id' => $user->id, 'content' => $request->input('content'), 'parent_id' => $parent_id]); $numComment = $article->comments()->count(); $article->update(['num_comment' => $numComment]); $obj = $article; $model = 'article'; return ['hasCallback' => 1, 'callback' => 'article_comment', 'hasMsg' => 1, 'msgType' => '', 'msg' => $msg, 'returns' => ['newComment' => view('comment.comment', compact('newComment', 'article', 'user', 'obj', 'model'))->render(), 'nested' => $nested, 'numComment' => $numComment]]; }
/** * @param $id * @return \Illuminate\View\View */ public function show(Article $article) { //$article = Article::findOrFail($id); //dd($article); /* if (is_null($article)){ abort(404); }else { }*/ $comments = $article->comments()->latest('published_At')->get(); $uploadArray = $this->getUploadedContent($article); $upload_content = $uploadArray[0]; $upload_type = $uploadArray[1]; // set content-type //$img->header('Content-Type', 'image/jpg'); //dd($base64); return view('articles.show', compact('article', 'comments', 'upload_content', 'upload_type')); }
public function show(Article $article) { $comments = $article->comments()->with('user')->recent()->simplePaginate(10); $article->increment('view_count'); return view('articles.show', compact('article', 'comments')); }
public function addComment(Article $article, Request $request) { $validator = Validator::make($request->all(), ['content' => 'required']); if ($validator->passes()) { // TBD check user has write access to group $comment = $article->comments()->create(['content' => $request->content, 'postable_type' => 'App\\Article', 'postable_id' => $article->id, 'user_id' => Auth::user()->id]); if ($comment) { return $this->respondWithItem($article, new ArticleTransformer()); } } else { return $this->errorValidation($validator->messages); } }
public function addReply(Article $b) { $parent = Comment::find(2); $comment = new Comment(); $comment->body = 'MY DICK!'; $comment->user_id = '1'; $b->comments()->save($comment); $comment->makeChildOf($parent); Cache::tags('commentRoot-article-' . $b->id)->flush(); Clockwork::info('Cleared cache:' . 'commentRoot-article-' . $b->id); Cache::forget('commentTree-' . $comment->getRoot()->id); Clockwork::info('Cleared cache: ' . 'commentTree-' . $comment->getRoot()->id); return $comment->getRoot()->id; }
/** * Include comments. * * @param \App\Article $article * @param \League\Fractal\ParamBag|null $params * @return \League\Fractal\Resource\Collection * @throws \Exception */ public function includeComments(Article $article, ParamBag $params = null) { list($limit, $offset, $orderCol, $orderBy) = $this->calculateParams($params); $comments = $article->comments()->limit($limit)->offset($offset)->orderBy($orderCol, $orderBy)->get(); return $this->collection($comments, new \App\Transformers\CommentTransformer()); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Article $article, Comment $comment) { // $article->comments()->where('id', $comment->id)->delete(); $article->comments()->delete(); Session::flash('success', 'Comment deleted'); return Redirect::route('articles.show', $article->id); }