finally fixed serialization of conversions #189
This commit is contained in:
@@ -12,7 +12,7 @@ class Flight extends Resource
|
||||
$flight = parent::toArray($request);
|
||||
|
||||
// Return multiple measures so the client can pick what they want
|
||||
if(filled($this->distance) && $this->distance instanceof Distance) {
|
||||
if($this->distance instanceof Distance) {
|
||||
$flight['distance'] = $this->distance->toObject();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@ class Pirep extends Resource
|
||||
{
|
||||
$pirep = parent::toArray($request);
|
||||
|
||||
if (filled($this->distance) && $this->distance instanceof Distance) {
|
||||
if ($this->distance instanceof Distance) {
|
||||
$pirep['distance'] = $this->distance->toObject();
|
||||
}
|
||||
|
||||
if (filled($this->planned_distance) && $this->planned_distance instanceof Distance) {
|
||||
if ($this->planned_distance instanceof Distance) {
|
||||
$pirep['planned_distance'] = $this->planned_distance->toObject();
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,10 @@ class Flight extends BaseModel
|
||||
*/
|
||||
public function getDistanceAttribute()
|
||||
{
|
||||
if (!array_key_exists('distance', $this->attributes)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$distance = (float) $this->attributes['distance'];
|
||||
return new Distance($distance, Distance::STORAGE_UNIT);
|
||||
|
||||
@@ -109,6 +109,10 @@ class Pirep extends BaseModel
|
||||
*/
|
||||
public function getDistanceAttribute()
|
||||
{
|
||||
if(!array_key_exists('distance', $this->attributes)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$distance = (float) $this->attributes['distance'];
|
||||
return new Distance($distance, Distance::STORAGE_UNIT);
|
||||
@@ -138,6 +142,10 @@ class Pirep extends BaseModel
|
||||
*/
|
||||
public function getPlannedDistanceAttribute()
|
||||
{
|
||||
if (!array_key_exists('planned_distance', $this->attributes)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$distance = (float) $this->attributes['planned_distance'];
|
||||
return new Distance($distance, Distance::STORAGE_UNIT);
|
||||
|
||||
Reference in New Issue
Block a user