Add helper field() method to Pirep model
This commit is contained in:
@@ -5,15 +5,16 @@ namespace App\Models;
|
||||
use App\Interfaces\Model;
|
||||
use App\Models\Traits\HashIdTrait;
|
||||
use App\Support\Units\Distance;
|
||||
use Illuminate\Support\Collection;
|
||||
use PhpUnitsOfMeasure\Exception\NonNumericValue;
|
||||
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
|
||||
|
||||
/**
|
||||
* @property Airline airline
|
||||
* @property mixed flight_number
|
||||
* @property mixed route_code
|
||||
* @property mixed route_leg
|
||||
* @property FlightFields[] fields
|
||||
* @property Airline airline
|
||||
* @property mixed flight_number
|
||||
* @property mixed route_code
|
||||
* @property mixed route_leg
|
||||
* @property Collection fields
|
||||
*/
|
||||
class Flight extends Model
|
||||
{
|
||||
@@ -127,7 +128,7 @@ class Flight extends Model
|
||||
* @param $field_name
|
||||
* @return string
|
||||
*/
|
||||
public function field($field_name)
|
||||
public function field($field_name): string
|
||||
{
|
||||
$field = $this->fields->where('name', $field_name)->first();
|
||||
if($field) {
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\Enums\PirepState;
|
||||
use App\Models\Traits\HashIdTrait;
|
||||
use App\Support\Units\Distance;
|
||||
use App\Support\Units\Fuel;
|
||||
use Illuminate\Support\Collection;
|
||||
use PhpUnitsOfMeasure\Exception\NonNumericValue;
|
||||
use PhpUnitsOfMeasure\Exception\NonStringUnitName;
|
||||
|
||||
@@ -26,6 +27,7 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName;
|
||||
* @property integer flight_time In minutes
|
||||
* @property User user
|
||||
* @property Flight|null flight
|
||||
* @property Collection fields
|
||||
* @package App\Models
|
||||
*/
|
||||
class Pirep extends Model
|
||||
@@ -272,6 +274,21 @@ class Pirep extends Model
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a custom field value
|
||||
* @param $field_name
|
||||
* @return string
|
||||
*/
|
||||
public function field($field_name): string
|
||||
{
|
||||
$field = $this->fields->where('name', $field_name)->first();
|
||||
if ($field) {
|
||||
return $field['value'];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Foreign Keys
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user