From 0821258a2d962000759091bf14bb8a1358bfa9c2 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Thu, 29 Jun 2017 15:50:16 -0500 Subject: [PATCH] #21 FK wiring --- app/Models/Pirep.php | 23 +++++++++++-------- app/Models/PirepFieldValues.php | 9 ++++++++ app/Models/User.php | 5 ++++ .../2017_06_08_0000_create_users_table.php | 1 + 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/Models/Pirep.php b/app/Models/Pirep.php index 3d5abeeb..e54806dc 100644 --- a/app/Models/Pirep.php +++ b/app/Models/Pirep.php @@ -68,14 +68,9 @@ class Pirep extends Model * Foreign Keys */ - public function user() + public function arr_airport() { - return $this->belongsTo('App\Models\User', 'user_id'); - } - - public function flight() - { - return $this->belongsTo('App\Models\Flight', 'flight_id'); + return $this->belongsTo('App\Models\Airport', 'arr_airport_id'); } public function dpt_airport() @@ -83,9 +78,19 @@ class Pirep extends Model return $this->belongsTo('App\Models\Airport', 'dpt_airport_id'); } - public function arr_airport() + public function fields() { - return $this->belongsTo('App\Models\Airport', 'arr_airport_id'); + return $this->hasMany('App\Models\PirepFieldValues', 'pirep_id'); + } + + public function flight() + { + return $this->belongsTo('App\Models\Flight', 'flight_id'); + } + + public function user() + { + return $this->belongsTo('App\Models\User', 'user_id'); } } diff --git a/app/Models/PirepFieldValues.php b/app/Models/PirepFieldValues.php index 01826ac3..e18a3b18 100644 --- a/app/Models/PirepFieldValues.php +++ b/app/Models/PirepFieldValues.php @@ -42,4 +42,13 @@ class PirepFieldValues extends Model = [ 'name' => 'required', ]; + + /** + * Foreign Keys + */ + + public function pirep() + { + return $this->belongsTo('App\Models\Pirep', 'pirep_id'); + } } diff --git a/app/Models/User.php b/app/Models/User.php index e12402fc..246f4bd6 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -71,6 +71,11 @@ class User extends Authenticatable return $this->belongsTo('App\Models\Airport', 'curr_airport_id'); } + public function pireps() + { + return $this->hasMany('App\Models\Pirep', 'user_id'); + } + public function rank() { return $this->belongsTo('App\Models\Rank', 'rank_id'); diff --git a/database/migrations/2017_06_08_0000_create_users_table.php b/database/migrations/2017_06_08_0000_create_users_table.php index a6da0e27..198ed863 100755 --- a/database/migrations/2017_06_08_0000_create_users_table.php +++ b/database/migrations/2017_06_08_0000_create_users_table.php @@ -32,6 +32,7 @@ class CreateUsersTable extends Migration $table->timestamps(); $table->softDeletes(); + $table->index('email'); }); // Create table for storing roles