【问题标题】:Laravel Fractal does not return meta from include relationshipLaravel Fractal 不会从包含关系返回元数据
【发布时间】:2017-04-13 01:55:46
【问题描述】:

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

}

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

【问题讨论】:

    标签: php laravel-5.3 json-api thephpleague thephpleague-fractal


    【解决方案1】:

    这是 Fractal 的一个已知问题。

    问题

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

    拉取请求(打开)

    有一个公开的拉取请求,包括 meta 用于关系。

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

    【讨论】:

      猜你喜欢
      • 2020-02-16
      • 2015-01-16
      • 2016-10-26
      • 1970-01-01
      • 1970-01-01
      • 2016-03-25
      • 2019-06-05
      • 1970-01-01
      • 2020-03-04
      相关资源
      最近更新 更多