flugg / laravel-responder

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

Load relation as #112

Open Hesesses opened 6 years ago

Hesesses commented 6 years ago

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[].

flugg commented 6 years ago

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?

Hesesses commented 4 years ago

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