laravel-responder icon indicating copy to clipboard operation
laravel-responder copied to clipboard

Load relation as

Open Hesesses opened this issue 7 years ago • 2 comments

Is it possible to load relation as 'something'

For example I have these relations

protected $relations = [
      'users' => UserTransformer::class,
      'activeUsers' => UserTransformer::class
]

I'm sending get request to /teams?with=users or /teams?with=activeUsers and would like to have response from both requests as teams[].users[].

Hesesses avatar Mar 02 '18 16:03 Hesesses

Hey! It’s currently not possible to rename relationships. However, you can create an includeUsers method that returns $team->activeUsers, however, I’m not sure how that would work with two relations referencing the same name. What should happen if you call teams?with=users,activeUsers?

flugg avatar Mar 05 '18 17:03 flugg

Sorry, I havent replied this earlier. If I remember correctly we ended up with the solution you suggested, so with=users,activeUsers works fine

Hesesses avatar May 22 '20 05:05 Hesesses