I have two models with a one-to-many relationship.
class User extends ConfideUser { public function shouts() { return $this->hasMany('Shout'); } } class Shout extends Eloquent { public function users() { return $this->belongsTo('User'); } }
Everything seems to be working fine. BUT, How do I get this to return a user object nested in scream objects? Now it returns only all my screams, but I do not have JSON access to the owned user model.
Route::get('api/shout', function() { return Shout::with('users')->get(); });
This simply returns this JSON with no user object for each call:
[{"id":"1","user_id":"1","message":"A little test shout!","location":"K","created_at":"2013-05-23 19:51:44","updated_at":"2013-05-23 19:51:44"},{"id":"2","user_id":"1","message":"And here is an other shout that is a little bit longer...","location":"S","created_at":"2013-05-23 19:51:44","updated_at":"2013-05-23 19:51:44"}]
Emin source share