【发布时间】:2015-07-30 10:46:51
【问题描述】:
我有以下数据库表:
季节
- 身份证
- 号码
团队
- 身份证
- 姓名
排名
- 身份证
- season_id
- team_id
问题是,我怎样才能让一个赛季的所有球队都进入积分榜。目前,我正在以这种方式让所有团队:
$teams = [];
$standings = $season->standings;
foreach($standings as $standing){
$teams[] = $standing->team;
}
有没有办法使用 Eloquent 关系来做到这一点?我试过 HasManyThrough 没有成功。这些是我的模型目前的样子:
class Season extends Eloquent{
public function standings(){
return $this->hasMany('Standing');
}
}
class Standing extends Eloquent{
public function team(){
return $this->belongsTo('Team');
}
}
class Team extends Eloquent{
public function standings(){
return $this->belongsToMany('Standing');
}
}
【问题讨论】:
标签: laravel laravel-4 orm eloquent laravel-5