Laravel 5.1-返回具有多种关系的雄辩模型


Laravel 5.1 - return eloquent model with multiple relationships

我有以下模型Show、Presenter、Image。

节目可以有多个主持人。演示者有一个图像。

我可以这样做来获得一个演示者的图像:

$presenter = Presenter::with('image)->find(1);

我可以这样做来和主持人一起表演:

$show = Show::with('presenters')->find(1);

有没有一种方法可以让我在一份声明中与主持人和他们的形象一起返回节目?

您可以使用点表示法来急切地加载嵌套关系。

$show = Show::with('presenters.image')->find(1);

如果你定义了你的关系,你可以很容易地在一个查询中得到它们:

http://laravel.com/docs/5.1/eloquent-relationships#querying-关系