implements ArrayAccess for casting to type #189
This commit is contained in:
@@ -110,7 +110,7 @@ class Pirep extends BaseModel
|
||||
public function getDistanceAttribute()
|
||||
{
|
||||
try {
|
||||
$distance = (float)$this->attributes['distance'];
|
||||
$distance = (float) $this->attributes['distance'];
|
||||
return new Distance($distance, 'mi');
|
||||
} catch (NonNumericValue $e) {
|
||||
return 0;
|
||||
@@ -119,6 +119,19 @@ class Pirep extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the distance unit, convert to our internal default unit
|
||||
* @param $value
|
||||
*/
|
||||
public function setDistanceAttribute($value): void
|
||||
{
|
||||
if ($value instanceof Distance) {
|
||||
$this->attributes['distance'] = $value->toUnit(Distance::STORAGE_UNIT);
|
||||
} else {
|
||||
$this->attributes['distance'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the planned_distance in a converter class
|
||||
* @return int|Distance
|
||||
@@ -135,6 +148,19 @@ class Pirep extends BaseModel
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the distance unit, convert to our internal default unit
|
||||
* @param $value
|
||||
*/
|
||||
public function setPlannedDistanceAttribute($value)
|
||||
{
|
||||
if ($value instanceof Distance) {
|
||||
$this->attributes['distance'] = $value->toUnit(Distance::STORAGE_UNIT);
|
||||
} else {
|
||||
$this->attributes['distance'] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do some cleanup on the route
|
||||
* @param $route
|
||||
|
||||
Reference in New Issue
Block a user