I would like to implement something similar to what was asked in this question in Laravel 4, where the player/ resource can have more than one team/ , and vice versa.
In an ideal world, I could request
players/1/teams
and return some JSON as follows:
{ player: { id: 1, name: 'Bob', sport: 'Curling', teams: [ { id: 1, name: 'Northern Curling Soc.', age: 2}, { id:2, name: 'Southern Curling Soc.', age: 4 } ] }
or
teams/{id}/players and get correlative.
Obviously, if I used Laravel views, I could just call $player->teams and everything will be fine, but this is for the JSON API, so everything should be in front.
I also need to be able to break down related results, although this is probably another question.
How can I do this with Laravel?
Thanks for any help!
source share