/** * Show the form required by an ajax request. * * @param $parent * @param FormBuilder $formBuilder * * @return \Illuminate\Http\Response */ public function add(FormBuilder $formBuilder, $parent) { $articleComment = ArticleComment::whereId($parent)->get(['article_id'])->first(); $slug = Article::whereId($articleComment->article_id)->get(['slug'])->first(); $form = $formBuilder->create('\\App\\Http\\Forms\\ArticleCommentForm', ['method' => 'POST', 'id' => 'article_comment_form', 'url' => route('articles.comment.store')]); $form->add('slug', 'hidden', ['value' => $slug->slug, 'attr' => ['id' => 'slug']]); $form->add('parent_id', 'hidden', ['value' => $parent, 'attr' => ['id' => 'parent_id']]); $form->add('save', 'submit', ['label' => 'Add your comment']); return response()->view('articles.ajax_article_comment_show', compact('form')); }
/** * Get the comments of an article detail * * @return array */ protected function _getArticleCommentsNumber() { if ($this->article->count() == 0) { return array(); } $articleCommentCount = array(); foreach ($this->article as $comment) { $articleCommentCount[$comment->id] = ArticleComment::whereArticleId($comment->id)->whereApproved('1')->count(); } return $articleCommentCount; }