Laravel 9 Update (#1413)
Update to Laravel 9 and PHP 8+ Co-authored-by: B.Fatih KOZ <fatih.koz@gmail.com>
This commit is contained in:
@@ -3,10 +3,13 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Contracts\Model;
|
||||
use App\Models\Casts\FuelCast;
|
||||
use App\Models\Enums\AircraftStatus;
|
||||
use App\Models\Traits\ExpensableTrait;
|
||||
use App\Models\Traits\FilesTrait;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
|
||||
/**
|
||||
@@ -32,9 +35,10 @@ use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
*/
|
||||
class Aircraft extends Model
|
||||
{
|
||||
use BelongsToThrough;
|
||||
use ExpensableTrait;
|
||||
use FilesTrait;
|
||||
use BelongsToThrough;
|
||||
use HasFactory;
|
||||
|
||||
public $table = 'aircraft';
|
||||
|
||||
@@ -50,6 +54,7 @@ class Aircraft extends Model
|
||||
'flight_time',
|
||||
'mtow',
|
||||
'zfw',
|
||||
'fuel_onboard',
|
||||
'status',
|
||||
'state',
|
||||
];
|
||||
@@ -58,11 +63,12 @@ class Aircraft extends Model
|
||||
* The attributes that should be casted to native types.
|
||||
*/
|
||||
protected $casts = [
|
||||
'subfleet_id' => 'integer',
|
||||
'mtow' => 'float',
|
||||
'zfw' => 'float',
|
||||
'flight_time' => 'float',
|
||||
'state' => 'integer',
|
||||
'subfleet_id' => 'integer',
|
||||
'mtow' => 'float',
|
||||
'zfw' => 'float',
|
||||
'flight_time' => 'float',
|
||||
'fuel_onboard' => FuelCast::class,
|
||||
'state' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -78,43 +84,51 @@ class Aircraft extends Model
|
||||
];
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return Attribute
|
||||
*/
|
||||
public function getIdentAttribute(): string
|
||||
public function active(): Attribute
|
||||
{
|
||||
return $this->registration.' ('.$this->icao.')';
|
||||
return Attribute::make(
|
||||
get: fn ($_, $attr) => $attr['status'] === AircraftStatus::ACTIVE
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* See if this aircraft is active
|
||||
*
|
||||
* @return bool
|
||||
* @return Attribute
|
||||
*/
|
||||
public function getActiveAttribute(): bool
|
||||
public function icao(): Attribute
|
||||
{
|
||||
return $this->status === AircraftStatus::ACTIVE;
|
||||
return Attribute::make(
|
||||
set: fn ($value) => strtoupper($value)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Capitalize the ICAO when set
|
||||
*
|
||||
* @param $icao
|
||||
* @return Attribute
|
||||
*/
|
||||
public function setIcaoAttribute($icao): void
|
||||
public function ident(): Attribute
|
||||
{
|
||||
$this->attributes['icao'] = strtoupper($icao);
|
||||
return Attribute::make(
|
||||
get: fn ($_, $attrs) => $attrs['registration'].' ('.$attrs['icao'].')'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the landing time in carbon format if provided
|
||||
* Return the landing time
|
||||
*
|
||||
* @return Carbon|null
|
||||
* @return Attribute
|
||||
*/
|
||||
public function getLandingTimeAttribute()
|
||||
public function landingTime(): Attribute
|
||||
{
|
||||
if (array_key_exists('landing_time', $this->attributes) && filled($this->attributes['landing_time'])) {
|
||||
return new Carbon($this->attributes['landing_time']);
|
||||
}
|
||||
return Attribute::make(
|
||||
get: function ($_, $attrs) {
|
||||
if (array_key_exists('landing_time', $attrs) && filled($attrs['landing_time'])) {
|
||||
return new Carbon($attrs['landing_time']);
|
||||
}
|
||||
|
||||
return $attrs['landing_time'];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user