In Laravel (with Fractal Transformers), I'm trying to figure out how to handle nested resources exactly. Lets say I have these routes:
Route::resource('user', 'UserController');
Route::resource('user.activity', 'UserActivityController');
So if I wanted to get all users, the uri is /user, And if I want User 5, it's /user/5
Now, if I want the Activity for a User, the uri is user/1/activity.
Here's where I get a little confused. In the UserActivityController, you might have:
public function index($user_id)
{
$user = $this->user->find($user_id)->activity;
return $this->respondWithItem($user, $this->transformer);
}
So here's what I'm confused about:
1) For each nested resource, do I keep fetching the top parent resource (User in this case)? Lets say user has nested resources 3 or 4 levels deep (i.e. /user/1/activity/5/mentions/6/somethng-else)? Does each Resource Controller just need to keep starting from the top and working down?
2) As I'm using Fractal, is has support for includes which allows me to load related data as needed by appending certain data to includes in the query string. In fact, it's so flexible that I feel I could use a base (like User) and get every other bit of data I need from clever include usage. So, is it preferable to just do this rather than using sub resources and sub resource controllers?
user. This will cause conflict.