本文整理汇总了PHP中app\Post::comments方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::comments方法的具体用法?PHP Post::comments怎么用?PHP Post::comments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::comments方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
public function store(Request $request, Post $post)
{
$comment = Comment::create($request->all());
$post->comments()->save($comment);
Score::create(['user_id' => Auth::user()->id, 'reference' => 'comment', 'score' => 2]);
Auth::user()->increment('scores', 2);
return redirect()->to('posts/' . $post->slug);
}
示例2: getComments
public function getComments(Post $post)
{
$comments = $post->comments()->getResults()->groupBy('parent_id');
$rootComments = $comments->get(null)->groupBy('id');
$filterOutKeys = array('');
$filteredArr = array_diff_key($comments->toArray(), array_flip($filterOutKeys));
return ['root_comments' => $rootComments, 'child_comments' => $filteredArr];
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Requests\Comment $request, Post $post)
{
$comment = new Comment($request->all());
$post->comments()->save($comment);
return redirect($post->slug);
}
示例4: postGroupDelete
public function postGroupDelete(Request $request, Post $post, Comment $comment)
{
if ($request->user()->cannot('delete-problem-comment', [$post, $comment])) {
return ['hasCallback' => 0, 'callback' => '', 'hasMsg' => 1, 'msg' => 'شما مجوز حذف این پست را ندارید.', 'msgType' => 'danger', 'returns' => ['num_comments' => '']];
}
$comment->delete();
$num_comments = $post->comments()->count();
$post->update(['num_comment' => $num_comments]);
return ['hasCallback' => 1, 'callback' => 'post_comment_delete', 'hasMsg' => 0, 'msg' => '', 'msgType' => '', 'returns' => ['num_comments' => $num_comments]];
}