#406 Refactor bids (#432)

* Add flight_id column to pireps table

* Refactor PIREPs and bids closes 406

* Formatting
This commit is contained in:
Nabeel S
2019-11-05 11:44:31 -05:00
committed by GitHub
parent db087d0ccb
commit f5183babf6
35 changed files with 967 additions and 798 deletions

View File

@@ -22,7 +22,10 @@ use Illuminate\Support\Collection;
* @property Collection fares
* @property Collection subfleets
* @property int days
* @property int distance
* @property int flight_time
* @property string route
* @property int level
* @property Airport dpt_airport
* @property Airport arr_airport
* @property Airport alt_airport

View File

@@ -150,6 +150,28 @@ class Pirep extends Model
PirepState::DELETED,
];
/**
* Create a new PIREP model from a given flight. Pre-populates the fields
*
* @param \App\Models\Flight $flight
*
* @return \App\Models\Pirep
*/
public static function fromFlight(Flight $flight)
{
return new self([
'flight_id' => $flight->id,
'airline_id' => $flight->airline_id,
'flight_number' => $flight->flight_number,
'route_code' => $flight->route_code,
'route_leg' => $flight->route_leg,
'dpt_airport_id' => $flight->dpt_airport_id,
'arr_airport_id' => $flight->arr_airport_id,
'route' => $flight->route,
'level' => $flight->level,
]);
}
/**
* Get the flight ident, e.,g JBU1900
*
@@ -277,10 +299,16 @@ class Pirep extends Model
/**
* Look up the flight, based on the PIREP flight info
*
* @param mixed $value
*
* @return Flight|null
*/
public function getFlightAttribute(): ?Flight
/*public function getFlightAttribute(): ?Flight
{
if (!empty($this->flight_id)) {
return Flight::find($this->flight_id);
}
$where = [
'airline_id' => $this->airline_id,
'flight_number' => $this->flight_number,
@@ -296,7 +324,7 @@ class Pirep extends Model
}
return Flight::where($where)->first();
}
}*/
/**
* Set the amount of fuel used
@@ -412,6 +440,11 @@ class Pirep extends Model
return $this->belongsTo(Airline::class, 'airline_id');
}
public function flight()
{
return $this->belongsTo(Flight::class, 'flight_id');
}
public function arr_airport()
{
return $this->belongsTo(Airport::class, 'arr_airport_id');

View File

@@ -12,6 +12,7 @@ use Laratrust\Traits\LaratrustUserTrait;
/**
* @property int id
* @property int pilot_id
* @property int airline_id
* @property string name
* @property string email
* @property string password