How to alias in Laravel Eager Loading
问题 I need to alias when I do a Laravel eager loading: $posts = Post::with(array('images as main_image' => function($query) // do not run { $query->where('number', '=', '0'); })) ->where('id', '=', $id) ->get(); return Response::json($posts); I need to to this because I want the JSON response like this: [ { "id": 126, "slug": "abc", "name": "abc", "created_at": "2014-08-08 08:11:25", "updated_at": "2014-08-28 11:45:07", "**main_image**": [ { "id": 223, "post_id": 126 ... } ] } ] It is possible?