Save PIREP route to ACARS data table #102
This commit is contained in:
@@ -14,6 +14,8 @@ class Acars extends BaseModel
|
||||
public $fillable = [
|
||||
'pirep_id',
|
||||
'type',
|
||||
'nav_type',
|
||||
'name',
|
||||
'log',
|
||||
'lat',
|
||||
'lon',
|
||||
@@ -29,6 +31,7 @@ class Acars extends BaseModel
|
||||
|
||||
public $casts = [
|
||||
'type' => 'integer',
|
||||
'nav_type' => 'integer',
|
||||
'lat' => 'float',
|
||||
'lon' => 'float',
|
||||
'heading' => 'integer',
|
||||
|
||||
@@ -18,9 +18,23 @@ class Navdata extends BaseModel
|
||||
];
|
||||
|
||||
public $casts = [
|
||||
'id' => 'string',
|
||||
'type' => 'integer',
|
||||
'lat' => 'float',
|
||||
'lon' => 'float',
|
||||
'freq' => 'float',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
/**
|
||||
* Make sure the ID is all caps
|
||||
*/
|
||||
static::creating(function (Navdata $model) {
|
||||
if (!empty($model->id)) {
|
||||
$model->id = strtoupper($model->id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,8 @@ class Pirep extends BaseModel
|
||||
'flight_number' => 'required',
|
||||
'dpt_airport_id' => 'required',
|
||||
'arr_airport_id' => 'required',
|
||||
'notes' => 'nullable',
|
||||
'route' => 'nullable',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -70,10 +72,12 @@ class Pirep extends BaseModel
|
||||
public function getIdentAttribute()
|
||||
{
|
||||
$flight_id = $this->airline->code;
|
||||
if ($this->flight_id) {
|
||||
$flight_id .= $this->flight->flight_number;
|
||||
} else {
|
||||
if(!empty($this->flight_number)) {
|
||||
$flight_id .= $this->flight_number;
|
||||
} else {
|
||||
if ($this->flight_id) {
|
||||
$flight_id .= $this->flight->flight_number;
|
||||
}
|
||||
}
|
||||
|
||||
return $flight_id;
|
||||
|
||||
@@ -7,19 +7,27 @@ use Hashids\Hashids;
|
||||
|
||||
trait HashId
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Hashids\HashidsException
|
||||
*/
|
||||
protected static function createNewHashId()
|
||||
{
|
||||
$hashids = new Hashids('', 12);
|
||||
$mt = str_replace('.', '', microtime(true));
|
||||
return $hashids->encode($mt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register callbacks
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model)
|
||||
{
|
||||
static::creating(function ($model) {
|
||||
$key = $model->getKeyName();
|
||||
|
||||
if (empty($model->{$key})) {
|
||||
$hashids = new Hashids('', 12);
|
||||
$mt = str_replace('.', '', microtime(true));
|
||||
$id = $hashids->encode($mt);
|
||||
|
||||
$id = static::createNewHashId();
|
||||
$model->{$key} = $id;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user