php - Laravel eager loading - relationship query -
php - Laravel eager loading - relationship query -
say have 3 tables blog, post, comment has corresponding models blog, post, comment. no here relation between them:
blog has many post, posts() post belongs blog, blog() post has many comment, comments() comment belongs post post() now want execute query this:
blog::with(array('posts.comments' => function($q) { //query post columns })->find(1); as know $q corresponding comment table. there way query post table?
query nested relation this:
$blog = blog::with(['posts' => function ($q) { $q->where('column','value'); // query posts table }, 'posts.comments' => function ($q) { $q->where('commentscolumn','anothervalue'); // query comments table }])->find(1); eloquent load posts accordingly, fetch comments posts.
php laravel orm laravel-4
Comments
Post a Comment