【发布时间】:2017-01-13 21:55:12
【问题描述】:
这是我的数据库架构
我有这些模型:
- 管理员
- 用户
- 下注
- 匹配
- 团队
我很困惑如何在模型中定义 matches 和 teams 之间的关系
这是我到现在为止所做的......
User.php
public function bets()
{
return $this->hasMany('\App\Bet');
}
Bet.php
public function user()
{
return $this->belongsTo('\App\User');
}
public function match()
{
return $this->belongsTo('\App\Match');
}
Match.php
public function bets()
{
return $this->hasMany('\App\Bet');
}
//?????????????
Team.php
//?????????????
实际上我需要的是应该在
Team.php 和Match.php 中放置而不是//???... 的代码,以便我可以轻松地做这些事情......
$team->matches();
$match->team1();
$match->team2();
谢谢
【问题讨论】:
标签: php database laravel laravel-5.2 database-relations