有没有办法在 Laravel 中合并两个关系?
目前是这样设置的,但我能否返回两个合并的关系?
public function CompetitionsHome() {
return $this->HasMany( 'Competition', 'home_team_id' );
}
public function CompetitionsGuest() {
return $this->HasMany( 'Competition', 'guest_team_id' );
}
public function Competitions() {
// return both CompetitionsHome & CompetitionsGuest
}
App\User::find(1)->with('competitions')
,但您可以执行App\User::find(1)->with('competitions_guest')
(除非有语法错误)。 - daraulprotected $appends = ['competitions'];
属性呢? - Potherca