Move the model callbacks into Observables; reduce caching since it held balances incorrectly

This commit is contained in:
Nabeel Shahzad
2018-03-18 20:37:35 -05:00
parent 6b002f24a8
commit 36ea12e135
25 changed files with 336 additions and 266 deletions

View File

@@ -4,7 +4,6 @@ namespace App\Models;
use App\Models\Enums\AircraftStatus;
use App\Models\Traits\ExpensableTrait;
use App\Support\ICAO;
/**
* @property mixed subfleet_id
@@ -58,27 +57,23 @@ class Aircraft extends BaseModel
];
/**
* Callbacks
* See if this aircraft is active
* @return bool
*/
protected static function boot()
{
parent::boot();
static::creating(function (Aircraft $model) {
if (!empty($model->icao)) {
$model->icao = strtoupper(trim($model->icao));
}
if(empty($model->hex_code)) {
$model->hex_code = ICAO::createHexCode();
}
});
}
public function getActiveAttribute()
public function getActiveAttribute(): bool
{
return $this->status === AircraftStatus::ACTIVE;
}
/**
* Capitalize the ICAO when set
* @param $icao
*/
public function setIcaoAttribute($icao): void
{
$this->attributes['icao'] = strtoupper($icao);
}
/**
* foreign keys
*/