我有以下几种关系:
演员< - > theater_play,演员< - >音乐剧,演员< - >芭蕾舞剧
如何在Laravel中创建单个数组来显示这些关系的所有结果?
我现在有了:
$actor->theaterPlays
,$actor->musicals
,$actor->balletPlays
我需要这样的东西:
$actor->allPerformances
编辑:
我必须通过名字或表演日期等来订购它们。
未经测试,但您应该能够在accessor模型中创建一个新的Actor
,它负责将所有类型合并在一起:
public function getAllPerformancesAttribute()
{
return $this->theaterPlays()
->get()
->merge($this->musicals()->get())
->merge($this->balletPlays()->get())
->all();
}