Trim ICAO/IATA names, clean up model fields

This commit is contained in:
Nabeel Shahzad 2018-01-03 22:04:51 -06:00
parent 507ce5f24f
commit fe4e200983
11 changed files with 48 additions and 62 deletions

View File

@ -34,6 +34,19 @@ class Aircraft extends BaseModel
'name' => 'required',
];
/**
* Callbacks
*/
protected static function boot()
{
parent::boot();
static::creating(function (Airport $model) {
if (!empty($model->icao)) {
$model->icao = strtoupper(trim($model->icao));
}
});
}
/**
* foreign keys
*/

View File

@ -48,22 +48,17 @@ class Airport extends BaseModel
];
/**
* Some fancy callbacks
* Callbacks
*/
protected static function boot()
{
parent::boot();
/**
* Make sure the ID is set to the ICAO
*/
static::creating(function (Airport $model) {
if(!empty($model->iata)) {
$model->iata = strtoupper($model->iata);
$model->iata = strtoupper(trim($model->iata));
}
$model->icao = strtoupper($model->icao);
$model->icao = strtoupper(trim($model->icao));
$model->id = $model->icao;
});
}

View File

@ -11,8 +11,6 @@ class Fare extends BaseModel
{
public $table = 'fares';
protected $dates = ['deleted_at'];
public $fillable = [
'code',
'name',
@ -24,8 +22,6 @@ class Fare extends BaseModel
];
protected $casts = [
'code' => 'string',
'name' => 'string',
'price' => 'float',
'cost' => 'float',
'capacity' => 'integer',

View File

@ -11,14 +11,11 @@ class FlightFields extends BaseModel
{
public $table = 'flight_fields';
protected $dates = ['deleted_at'];
public $fillable
= [
'flight_id',
'name',
'value',
];
public $fillable = [
'flight_id',
'name',
'value',
];
protected $casts = [];

View File

@ -45,7 +45,6 @@ class Pirep extends BaseModel
];
protected $casts = [
'id' => 'string',
'flight_time' => 'integer',
'planned_flight_time' => 'integer',
'level' => 'integer',

View File

@ -17,11 +17,6 @@ class PirepComment extends BaseModel
'comment',
];
/**
* Validation rules
*
* @var array
*/
public static $rules = [
'comment' => 'required',
];

View File

@ -18,7 +18,6 @@ class PirepField extends BaseModel
];
protected $casts = [
'name' => 'string',
'required' => 'boolean',
];

View File

@ -11,35 +11,16 @@ class PirepFieldValues extends BaseModel
{
public $table = 'pirep_field_values';
public $fillable
= [
'pirep_id',
'name',
'value',
'source',
];
public $fillable = [
'pirep_id',
'name',
'value',
'source',
];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts
= [
'name' => 'string',
'value' => 'string',
'source' => 'string',
];
/**
* Validation rules
*
* @var array
*/
public static $rules
= [
'name' => 'required',
];
public static $rules = [
'name' => 'required',
];
/**
* Foreign Keys

View File

@ -21,7 +21,6 @@ class Rank extends BaseModel
];
protected $casts = [
'name' => 'string',
'hours' => 'integer',
'auto_approve_acars' => 'bool',
'auto_approve_manual' => 'bool',
@ -29,8 +28,8 @@ class Rank extends BaseModel
];
public static $rules = [
'name' => 'required',
'hours' => 'required',
'name' => 'required',
'hours' => 'required|integer',
];
public function subfleets() {

View File

@ -17,18 +17,27 @@ class Setting extends BaseModel
'description',
];
public static $rules = [
'name' => 'required',
'key' => 'required',
'group' => 'required',
];
/**
* @param $key
* @return mixed
*/
public static function formatKey($key)
{
return str_replace('.', '_', strtolower($key));
}
/**
* Callbacks
*/
protected static function boot()
{
parent::boot();
/**
* Make sure any dots are replaced with underscores
*/
static::creating(function (Setting $model) {
if (!empty($model->id)) {
$model->id = Setting::formatKey($model->id);

View File

@ -16,6 +16,9 @@ class Subfleet extends BaseModel
'name',
'type',
'fuel_type',
'cargo_capacity',
'fuel_capacity',
'gross_weight',
];
/**