2017-08-13 22 views
0

、私はボクシングの結果のウェブサイトを作成しています、私は結果過去のボクサーを取得しようとしていますが、関係に苦しんでいます...例えばLaravel関係

、ボクサーは、多くのイベントを持つことができます(戦い)、1つの結果(勝利、引き分け、敗北)と1人の対戦相手を持つ。私は相手の情報と、ボクサーの結果のすべてを表示する

をしようとしています、私はボクサーのテーブルを持っている構造(必要に応じて関係IDを追加することができます)

Schema::create('events', function (Blueprint $table) { 
     $table->increments('id'); 
     $table->string('name'); 
     $table->date('date'); 
     $table->string('location'); 
     $table->timestamps(); 
     $table->softDeletes(); 
    }); 

とイベントがあり

Schema::create('boxers', function (Blueprint $table) { 
     $table->increments('id'); 
     $table->string('name'); 
     $table->string('status'); 
     $table->string('division'); 
     $table->string('stance'); 
     $table->date('dob'); 
     $table->integer('height'); 
     $table->string('nationality'); 
     $table->string('residence'); 
     $table->string('birthplace'); 
     $table->timestamps(); 
     $table->softDeletes(); 
    }); 

と私が取得するために追加して変更する必要がありますどのような結果

Schema::create('results', function (Blueprint $table) { 
     $table->increments('id'); 
     $table->integer('user_id'); 
     $table->integer('event_id'); 
     $table->string('result'); 
     $table->timestamps(); 
     $table->softDeletes(); 
    }); 

関係が正しく働くか?

答えて

0

イベントは通常hasMany戦い(多くのカードでの戦い)、各戦闘hasMany(2人)の選手。だからあなたの戦い/アスリートの関係は多対多(戦闘機は自分のキャリアを通して多くの戦いを持っている)だろう。 fight_idathlete_idの列を持つピボットテーブルathletes_fightsを作成します。さらに、このピボットテーブルはwinner_iddrawの列を持つことができます。戦いが抽選の場合、Drawはデフォルトで0,1になります。それはwin_method(このために別のテーブルを作成してwin_method_idとすることもできます)、win_roundwin_timeを持つこともできます。

Laravelドキュメントの関係セクションをチェックしてください。

だからあなたのモデルが Event Fight Athlete

..だろう