Laravel Fractal does not return meta from include relationship

This is my PostTransformer , where I included the relationship

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

This should be related to the ratio of comments to meta. But the problem here is that I did not get the meta in inlcuded relationships. If anyone can help me with this.

+6
source share
1 answer

This is a known issue with Fractal.

Problem

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

Pull Request (Open)

There is an open pull request here to enable meta for relationships.

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

0
source

Source: https://habr.com/ru/post/1012716/


All Articles