Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Matches Tables
- class CreateMatchesTable extends Migration
- {
- /**
- * Run the migrations.
- *
- * @return void
- */
- public function up()
- {
- Schema::create('matches', function (Blueprint $table) {
- $table->increments('id');
- $table->integer('visitor_id')->references('id')->on('teams');
- $table->integer('local_id')->references('id')->on('teams');
- $table->timestamp('match_date');
- $table->timestamps();
- });
- }
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::dropIfExists('matches');
- }
- }
- // Team Table
- class CreateTeamsTable extends Migration
- {
- /**
- * Run the migrations.
- *
- * @return void
- */
- public function up()
- {
- Schema::create('teams', function (Blueprint $table) {
- $table->increments('id');
- $table->string('name')->unique();
- $table->string('email')->unique();
- $table->string('phone');
- $table->string('website');
- $table->timestamps();
- });
- }
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::dropIfExists('teams');
- }
- }
- // Match Model
- class Match extends Model
- {
- protected $fillable = ['visitor_id', 'local_id', 'match_date'];
- public function team()
- {
- return $this->belongsTo(\App\Models\Team::class);
- }
- }
- // Team Model
- class Team extends Model
- {
- protected $fillable = ['name', 'email', 'phone', 'website'];
- public function local_matches()
- {
- return $this->hasMany(\App\Models\Match::class, 'local_id', 'id');
- }
- public function visitor_matches()
- {
- return $this->hasMany(\App\Models\Match::class, 'visitor_id', 'id');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement