flugg / laravel-responder

A Laravel Fractal package for building API responses, giving you the power of Fractal with Laravel's elegancy.
MIT License
861 stars 86 forks source link

Nested Relationship with includeRelationship Method #164

Open GramParallelo opened 4 years ago

GramParallelo commented 4 years ago

Hello,

First off, Thanks for the package!

In reducing query count I found that I didn't want eager-load a nested relationship. The following pseudo code hopefully explains the situation.

/// PostController
responder()->success($posts, PostTransformer::class)->with('comments.user')->response();

/// PostTransformer 
relations = ['comments' => CommentsTransformer::class']

/// CommentsTransformer
relations = ['user' => UserTransformer::class];
includeUser() { // ... do whatever, ex. grab user from cache instead of eager-load // }

Let me know, thanks!