渴望在Laravel中加载多个关系
问题描述:
I need to eager load multiple relationships in Laravel, but I can't find out how to do it. In Laravel Doc, it shows how to do it only for one relationship, like:
$books = Book::with('author.contacts')->get();
I need something like:
$books = Book::with(array('author'=>array('contacts', 'groups', 'orders')))->get();
Any ideas?
我需要在Laravel中加载多个关系,但我找不到如何做到这一点。 在Laravel Doc中,它显示了如何仅针对一种关系执行此操作,例如: p>
我需要类似的东西: p>
任何想法? p>
$ books = Book :: with('author.contacts') - > get( ); code> p>
$ books = Book :: with(array('author'= >数组('contacts','groups','orders'))) - > get(); code> p>
答
Try this:
$books = Book::with('author.contacts','author.groups', 'author.orders')->get();