6

这是我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();
    }

}

这也应该导致评论与元的关系。但这里的问题是我没有得到包含关系的元数据。如果有人可以帮助我解决这个问题。

4

1 回答 1

0

这是 Fractal 的一个已知问题。

问题

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

拉取请求(打开)

有一个开放的拉取请求包括meta关系。

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

于 2017-04-07T09:23:30.467 回答