Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel-具有复合主键的HasOneThrough_Php_Laravel_Eloquent_Has One Through - Fatal编程技术网

Php Laravel-具有复合主键的HasOneThrough

Php Laravel-具有复合主键的HasOneThrough,php,laravel,eloquent,has-one-through,Php,Laravel,Eloquent,Has One Through,我正在开发一个应用程序,人们可以在其中查看体育游戏。这些表具有复合主键。以下是表的相关属性的外观: | Game | Team | League_Team | |---------------------------|-------------|----------------| | id (PK) | id (PK) | league_id (PK) | | league_id (PK)

我正在开发一个应用程序,人们可以在其中查看体育游戏。这些表具有复合主键。以下是表的相关属性的外观:

| Game                      | Team        | League_Team    |
|---------------------------|-------------|----------------|
| id (PK)                   | id (PK)     | league_id (PK) |
| league_id (PK)            | name        | team_id (PK)   |
| home_id  (season_team_id) | ...         | season_team_id |
| guest_id (season_team_id) |             | ...            |
| ...                       |             |                |
| ...                       |             |                |
所以我的目标是让所有的比赛都和主客队在一起。。。所以它应该看起来像这个
Game::with('homeTeam')->with('guestTeam')->

怎么可能得到这种关系呢?我试着通过hasOneThrough,但我不知道它如何与复合主键一起工作

谢谢你的帮助

编辑

$primaryKey
属性外,所有模型均为空

博弈模型

protected$primaryKey=['id','league_id']
公共函数homeTeam(){/…}

public function up()
{
    Schema::create('basketball_games', function (Blueprint $table) {
        $table->unsignedInteger('id');
        $table->unsignedInteger('league_id')->nullable();
        $table->dateTime('date');
        $table->unsignedInteger('home_id');
        $table->unsignedInteger('guest_id');


        $table->primary(['id','league_id']);

        // Foreign Keys
        $table->foreign('league_id')->references('id')->on('basketball_leagues');

        $table->timestamps();
    });
}
团队模式

空的

联赛队

protected$primaryKey=['league\u id','team\u id']

public function up()
{
    Schema::create('basketball_league_teams', function (Blueprint $table) {
        $table->unsignedInteger('league_id');
        $table->unsignedInteger('team_id');
        $table->unsignedInteger('season_team_id');
        $table->string('name');
        $table->timestamps();

        $table->primary(['league_id','team_id']);

        // Foreign Keys
        $table->foreign('league_id')->references('id')->on('basketball_leagues');
        $table->foreign('team_id')->references('id')->on('basketball_teams');
    });
}

请编辑问题并发布所有三个模型及其表迁移。我已将所有内容添加到问题中@你有什么建议吗?谢谢
public function up()
{
    Schema::create('basketball_league_teams', function (Blueprint $table) {
        $table->unsignedInteger('league_id');
        $table->unsignedInteger('team_id');
        $table->unsignedInteger('season_team_id');
        $table->string('name');
        $table->timestamps();

        $table->primary(['league_id','team_id']);

        // Foreign Keys
        $table->foreign('league_id')->references('id')->on('basketball_leagues');
        $table->foreign('team_id')->references('id')->on('basketball_teams');
    });
}