cleanup model relationship references

This commit is contained in:
Nabeel Shahzad 2018-01-08 09:22:12 -06:00
parent 8d65462084
commit 110d742714
13 changed files with 56 additions and 54 deletions

View File

@ -54,6 +54,6 @@ class Acars extends BaseModel
public function pirep() public function pirep()
{ {
return $this->belongsTo('App\Models\Pirep', 'pirep_id'); return $this->belongsTo(Pirep::class, 'pirep_id');
} }
} }

View File

@ -53,11 +53,11 @@ class Aircraft extends BaseModel
public function airport() public function airport()
{ {
return $this->belongsTo('App\Models\Airport', 'airport_id'); return $this->belongsTo(Airport::class, 'airport_id');
} }
public function subfleet() public function subfleet()
{ {
return $this->belongsTo('App\Models\Subfleet', 'subfleet_id'); return $this->belongsTo(Subfleet::class, 'subfleet_id');
} }
} }

View File

@ -38,10 +38,8 @@ class Fare extends BaseModel
*/ */
public function subfleets() { public function subfleets() {
return $this->belongsToMany( return $this->belongsToMany(Subfleet::class, 'subfleet_fare')
'App\Models\Subfleet', ->withPivot('price', 'cost', 'capacity');
'subfleet_fare'
)->withPivot('price', 'cost', 'capacity');
} }
} }

View File

@ -64,39 +64,37 @@ class Flight extends BaseModel
public function airline() public function airline()
{ {
return $this->belongsTo('App\Models\Airline', 'airline_id'); return $this->belongsTo(Airline::class, 'airline_id');
} }
public function dpt_airport() public function dpt_airport()
{ {
return $this->belongsTo('App\Models\Airport', 'dpt_airport_id'); return $this->belongsTo(Airport::class, 'dpt_airport_id');
} }
public function arr_airport() public function arr_airport()
{ {
return $this->belongsTo('App\Models\Airport', 'arr_airport_id'); return $this->belongsTo(Airport::class, 'arr_airport_id');
} }
public function alt_airport() public function alt_airport()
{ {
return $this->belongsTo('App\Models\Airport', 'alt_airport_id'); return $this->belongsTo(Airport::class, 'alt_airport_id');
} }
public function fares() public function fares()
{ {
return $this->belongsToMany( return $this->belongsToMany(Fare::class, 'flight_fare')
Fare::class, ->withPivot('price', 'cost', 'capacity');
'flight_fare'
)->withPivot('price', 'cost', 'capacity');
} }
public function fields() public function fields()
{ {
return $this->hasMany('App\Models\FlightFields', 'flight_id'); return $this->hasMany(FlightFields::class, 'flight_id');
} }
public function subfleets() public function subfleets()
{ {
return $this->belongsToMany('App\Models\Subfleet', 'subfleet_flight'); return $this->belongsToMany(Subfleet::class, 'subfleet_flight');
} }
} }

View File

@ -27,7 +27,7 @@ class FlightFields extends BaseModel
public function flight() public function flight()
{ {
return $this->belongsTo('App\Models\Flight', 'flight_id'); return $this->belongsTo(Flight::class, 'flight_id');
} }
} }

View File

@ -88,59 +88,59 @@ class Pirep extends BaseModel
public function acars() public function acars()
{ {
return $this->hasMany('App\Models\Acars', 'pirep_id') return $this->hasMany(Acars::class, 'pirep_id')
->where('type', AcarsType::FLIGHT_PATH) ->where('type', AcarsType::FLIGHT_PATH)
->orderBy('created_at', 'asc'); ->orderBy('created_at', 'asc');
} }
public function acars_logs() public function acars_logs()
{ {
return $this->hasMany('App\Models\Acars', 'pirep_id') return $this->hasMany(Acars::class, 'pirep_id')
->where('type', AcarsType::LOG) ->where('type', AcarsType::LOG)
->orderBy('created_at', 'asc'); ->orderBy('created_at', 'asc');
} }
public function acars_route() public function acars_route()
{ {
return $this->hasMany('App\Models\Acars', 'pirep_id') return $this->hasMany(Acars::class, 'pirep_id')
->where('type', AcarsType::ROUTE) ->where('type', AcarsType::ROUTE)
->orderBy('order', 'asc'); ->orderBy('order', 'asc');
} }
public function aircraft() public function aircraft()
{ {
return $this->belongsTo('App\Models\Aircraft', 'aircraft_id'); return $this->belongsTo(Aircraft::class, 'aircraft_id');
} }
public function airline() public function airline()
{ {
return $this->belongsTo('App\Models\Airline', 'airline_id'); return $this->belongsTo(Airline::class, 'airline_id');
} }
public function arr_airport() public function arr_airport()
{ {
return $this->belongsTo('App\Models\Airport', 'arr_airport_id'); return $this->belongsTo(Airport::class, 'arr_airport_id');
} }
public function dpt_airport() public function dpt_airport()
{ {
return $this->belongsTo('App\Models\Airport', 'dpt_airport_id'); return $this->belongsTo(Airport::class, 'dpt_airport_id');
} }
public function comments() public function comments()
{ {
return $this->hasMany('App\Models\PirepComment', 'pirep_id') return $this->hasMany(PirepComment::class, 'pirep_id')
->orderBy('created_at', 'desc'); ->orderBy('created_at', 'desc');
} }
public function fields() public function fields()
{ {
return $this->hasMany('App\Models\PirepFieldValues', 'pirep_id'); return $this->hasMany(PirepFieldValues::class, 'pirep_id');
} }
public function flight() public function flight()
{ {
return $this->belongsTo('App\Models\Flight', 'flight_id'); return $this->belongsTo(Flight::class, 'flight_id');
} }
public function pilot() public function pilot()
@ -154,13 +154,13 @@ class Pirep extends BaseModel
*/ */
public function position() public function position()
{ {
return $this->hasOne('App\Models\Acars', 'pirep_id') return $this->hasOne(Acars::class, 'pirep_id')
->where('type', AcarsType::FLIGHT_PATH) ->where('type', AcarsType::FLIGHT_PATH)
->latest(); ->latest();
} }
public function user() public function user()
{ {
return $this->belongsTo('App\Models\User', 'user_id'); return $this->belongsTo(User::class, 'user_id');
} }
} }

View File

@ -23,11 +23,11 @@ class PirepComment extends BaseModel
public function pirep() public function pirep()
{ {
return $this->belongsTo('App\Models\Pirep', 'pirep_id'); return $this->belongsTo(Pirep::class, 'pirep_id');
} }
public function user() public function user()
{ {
return $this->belongsTo('App\Models\User', 'user_id'); return $this->belongsTo(User::class, 'user_id');
} }
} }

View File

@ -28,6 +28,6 @@ class PirepFieldValues extends BaseModel
public function pirep() public function pirep()
{ {
return $this->belongsTo('App\Models\Pirep', 'pirep_id'); return $this->belongsTo(Pirep::class, 'pirep_id');
} }
} }

View File

@ -33,7 +33,7 @@ class Rank extends BaseModel
]; ];
public function subfleets() { public function subfleets() {
return $this->belongsToMany('App\Models\Subfleet', 'subfleet_rank') return $this->belongsToMany(Subfleet::class, 'subfleet_rank')
->withPivot('acars_pay', 'manual_pay'); ->withPivot('acars_pay', 'manual_pay');
} }
} }

View File

@ -51,10 +51,8 @@ class Subfleet extends BaseModel
public function fares() public function fares()
{ {
return $this->belongsToMany( return $this->belongsToMany(Fare::class, 'subfleet_fare')
Fare::class, ->withPivot('price', 'cost', 'capacity');
'subfleet_fare'
)->withPivot('price', 'cost', 'capacity');
} }
public function flights() public function flights()
@ -64,9 +62,7 @@ class Subfleet extends BaseModel
public function ranks() public function ranks()
{ {
return $this->belongsToMany( return $this->belongsToMany(Rank::class, 'subfleet_rank')
Rank::class, ->withPivot('acars_pay', 'manual_pay');
'subfleet_rank'
)->withPivot('acars_pay', 'manual_pay');
} }
} }

View File

@ -91,9 +91,9 @@ class User extends Authenticatable
*/ */
public function getGravatarAttribute() public function getGravatarAttribute()
{ {
$size = 80; $size = config('gravatar.size');
$default = 'https://en.gravatar.com/userimage/12856995/7c7c1da6387853fea65ff74983055386.png'; $default = config('gravatar.default');
return 'https://www.gravatar.com/avatar/' . return config('gravatar.url') .
md5(strtolower(trim($this->email))) . '?d=' . urlencode($default ) . '&s=' . $size; md5(strtolower(trim($this->email))) . '?d=' . urlencode($default ) . '&s=' . $size;
} }
@ -103,36 +103,36 @@ class User extends Authenticatable
public function airline() public function airline()
{ {
return $this->belongsTo('App\Models\Airline', 'airline_id'); return $this->belongsTo(Airline::class, 'airline_id');
} }
public function home_airport() public function home_airport()
{ {
return $this->belongsTo('App\Models\Airport', 'home_airport_id'); return $this->belongsTo(Airport::class, 'home_airport_id');
} }
public function current_airport() public function current_airport()
{ {
return $this->belongsTo('App\Models\Airport', 'curr_airport_id'); return $this->belongsTo(Airport::class, 'curr_airport_id');
} }
public function last_pirep() public function last_pirep()
{ {
return $this->belongsTo('App\Models\Pirep', 'last_pirep_id'); return $this->belongsTo(Pirep::class, 'last_pirep_id');
} }
public function bids() public function bids()
{ {
return $this->hasMany('App\Models\UserBid', 'user_id'); return $this->hasMany(UserBid::class, 'user_id');
} }
public function pireps() public function pireps()
{ {
return $this->hasMany('App\Models\Pirep', 'user_id'); return $this->hasMany(Pirep::class, 'user_id');
} }
public function rank() public function rank()
{ {
return $this->belongsTo('App\Models\Rank', 'rank_id'); return $this->belongsTo(Rank::class, 'rank_id');
} }
} }

View File

@ -19,11 +19,11 @@ class UserBid extends BaseModel
*/ */
public function flight() public function flight()
{ {
return $this->belongsTo('App\Models\Flight', 'flight_id'); return $this->belongsTo(Flight::class, 'flight_id');
} }
public function user() public function user()
{ {
return $this->belongsTo('App\Models\User', 'user_id'); return $this->belongsTo(User::class, 'user_id');
} }
} }

10
config/gravatar.php Normal file
View File

@ -0,0 +1,10 @@
<?php
/**
* Gravatar configs
*/
return [
'url' => 'https://www.gravatar.com/avatar/',
'default' => 'https://en.gravatar.com/userimage/12856995/7c7c1da6387853fea65ff74983055386.png',
'size' => 80,
];