Cleanup column types and assign Time class to fields #189

This commit is contained in:
Nabeel Shahzad
2018-02-11 20:38:56 -06:00
parent fd4407a798
commit 61af5fe226
8 changed files with 89 additions and 7 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Models;
use App\Support\Units\Distance;
use App\Support\Units\Time;
use PhpUnitsOfMeasure\Exception\NonNumericValue;
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
@@ -28,6 +29,7 @@ class Flight extends BaseModel
'arr_time',
'level',
'distance',
'flight_time',
'flight_type',
'route',
'notes',
@@ -39,6 +41,7 @@ class Flight extends BaseModel
'flight_number' => 'integer',
'level' => 'integer',
'distance' => 'float',
'flight_time' => 'integer',
'flight_type' => 'integer',
'has_bid' => 'boolean',
'active' => 'boolean',
@@ -108,6 +111,30 @@ class Flight extends BaseModel
}
}
/**
* @return Time
*/
public function getFlightTimeAttribute()
{
if (!array_key_exists('flight_time', $this->attributes)) {
return null;
}
return new Time($this->attributes['flight_time']);
}
/**
* @param $value
*/
public function setFlightTimeAttribute($value)
{
if ($value instanceof Time) {
$this->attributes['flight_time'] = $value->getMinutes();
} else {
$this->attributes['flight_time'] = $value;
}
}
/**
* Relationship
*/