Add a helper method in the Flight model to more easily get a custom value

This commit is contained in:
Nabeel Shahzad
2018-03-20 11:36:28 -05:00
parent 4e59bd0442
commit 712cb185b4

View File

@@ -9,10 +9,11 @@ use PhpUnitsOfMeasure\Exception\NonNumericValue;
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
/**
* @property Airline airline
* @property mixed flight_number
* @property mixed route_code
* @property mixed route_leg
* @property Airline airline
* @property mixed flight_number
* @property mixed route_code
* @property mixed route_leg
* @property FlightFields[] fields
*/
class Flight extends Model
{
@@ -121,6 +122,21 @@ class Flight extends Model
}
}
/**
* Return a custom field value
* @param $field_name
* @return string
*/
public function field($field_name)
{
$field = $this->fields->where('name', $field_name)->first();
if($field) {
return $field['value'];
}
return '';
}
/**
* Relationship
*/