Laravel Fractal不会从包括关系中返回META



这是我的 PostTransformer,其中我包含了关系

public function includeComments(Post $post)
{
    if (($post->is_paid == 1 && $post->haspaid == 1) || ($post->author == $this->params) || ($post->is_paid == 0)){
        $comments = Comment::where('post', $post->id)
            ->where('is_blocked', '=', 0)
            ->select('id',
                'text',
                'author',
                'post',
                'created_at',
                'updated_at',
                'book_id',
                DB::raw("if(comments.author=$this->params,'true','false') as isauthor"))
            ->orderBy('created_at', 'ASC')
            ->paginate(5);
        $commentTransformer = new CommentTransformer($this->params);
        $commentResource = $this->collection($comments, $commentTransformer, 'comment')->setMeta(['total'=>count($comments)]);
        return $commentResource;
    } elseif ($post->is_paid == 1 && $post->haspaid == 0) {
        return $this->null();
    }
}

这也应与Meta的评论有关。但是这里的问题是,我没有在陷入的关系中得到元。如果有人可以帮助我。

这是分形的已知问题。

问题

https://github.com/thephpleague/fractal/issues/339

拉请求(打开)

有一个打开的拉力请求,以包括meta的关系。

https://github.com/thephpleague/fractal/pull/350

最新更新