本文整理汇总了PHP中app\Article::comments方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::comments方法的具体用法?PHP Article::comments怎么用?PHP Article::comments使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Article
的用法示例。
在下文中一共展示了Article::comments方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: article
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();
}
示例2: includeComments
/**
* 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);
}
示例3: createTestStub
/**
* 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());
}
示例4: article
/**
* 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]];
}
示例5: show
/**
* @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'));
}
示例6: show
public function show(Article $article)
{
$comments = $article->comments()->with('user')->recent()->simplePaginate(10);
$article->increment('view_count');
return view('articles.show', compact('article', 'comments'));
}
示例7: addComment
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);
}
}
示例8: addReply
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;
}
示例9: includeComments
/**
* 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());
}
示例10: destroy
/**
* 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);
}