我有数据库中的模型结构,如下所示:
cellForRowAt
与玩家有关(此表总是必须有5个固定位置):
class Player extends Model
{
protected $table = 'players';
}
当我尝试像这样急切地加载class FormationPositions
{
protected $table = 'formation_position';
public function fpos1()
{
return $this->belongsTo(Player::class, 'fpos_1');
}
public function fpos2()
{
return $this->belongsTo(Player::class, 'fpos_2');
}
public function fpos3()
{
return $this->belongsTo(Player::class, 'fpos_3');
}
public function fpos4()
{
return $this->belongsTo(Player::class, 'fpos_4');
}
public function fpos5()
{
return $this->belongsTo(Player::class, 'fpos_5');
}
}
表:
FormationPositions
然后我有5个查询到数据库来加载这些对象,也许有一些方法可以将这个结构组合成一个查询与Elequent急切方式FormationPositions::with(['fpos1', 'fpos2', 'fpos3', 'fpos4', 'fpos5'])
并通过一个查询将数据加载到该对象?