refactor: update Flight model casts and relations
This commit is contained in:
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum FlightStatus:int
|
||||||
|
{
|
||||||
|
case AVAILABLE = 0;
|
||||||
|
|
||||||
|
case FULL = 1;
|
||||||
|
case CANCELLED = 2;
|
||||||
|
case DRAFT = 3;
|
||||||
|
case DELAYED = 4;
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum FlightTripType: int
|
||||||
|
{
|
||||||
|
case ONEWAY = 0;
|
||||||
|
case ROUNDTRIP = 1;
|
||||||
|
}
|
||||||
+57
-39
@@ -6,17 +6,20 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\FlightStatus;
|
||||||
|
use App\Enums\FlightTripType;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Flight
|
* Class Flight
|
||||||
*
|
*
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property int $airline_id
|
* @property int $airline_id
|
||||||
* @property int $origin_airport_id
|
* @property int $origin_airport_id
|
||||||
* @property int $destination_airport_id
|
* @property int $destination_airport_id
|
||||||
|
* @property int|null $file_id
|
||||||
* @property string $flight_number
|
* @property string $flight_number
|
||||||
* @property Carbon $departure_time
|
* @property Carbon $departure_time
|
||||||
* @property int $price
|
* @property int $price
|
||||||
@@ -24,9 +27,10 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
* @property int $status
|
* @property int $status
|
||||||
* @property Carbon $created_at
|
* @property Carbon $created_at
|
||||||
* @property Carbon $updated_at
|
* @property Carbon $updated_at
|
||||||
*
|
*
|
||||||
* @property Airline $airline
|
* @property Airline $airline
|
||||||
* @property Airport $airport
|
* @property Airport $airport
|
||||||
|
* @property File|null $file
|
||||||
* @property Collection|Booking[] $bookings
|
* @property Collection|Booking[] $bookings
|
||||||
* @property Collection|Tour[] $tours
|
* @property Collection|Tour[] $tours
|
||||||
*
|
*
|
||||||
@@ -34,47 +38,61 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
*/
|
*/
|
||||||
class Flight extends Model
|
class Flight extends Model
|
||||||
{
|
{
|
||||||
protected $table = 'flights';
|
protected $table = 'flights';
|
||||||
public static $snakeAttributes = false;
|
public static $snakeAttributes = false;
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'airline_id' => 'int',
|
'airline_id' => 'int',
|
||||||
'origin_airport_id' => 'int',
|
'origin_airport_id' => 'int',
|
||||||
'destination_airport_id' => 'int',
|
'destination_airport_id' => 'int',
|
||||||
'departure_time' => 'datetime',
|
'file_id' => 'int',
|
||||||
'price' => 'int',
|
'departure_time' => 'datetime',
|
||||||
'capacity' => 'int',
|
'price' => 'int',
|
||||||
'status' => 'int'
|
'capacity' => 'int',
|
||||||
];
|
'status' => FlightStatus::class,
|
||||||
|
'trip_type' => FlightTripType::class
|
||||||
|
];
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'airline_id',
|
'airline_id',
|
||||||
'origin_airport_id',
|
'origin_airport_id',
|
||||||
'destination_airport_id',
|
'destination_airport_id',
|
||||||
'flight_number',
|
'file_id',
|
||||||
'departure_time',
|
'flight_number',
|
||||||
'price',
|
'departure_time',
|
||||||
'capacity',
|
'price',
|
||||||
'status'
|
'capacity',
|
||||||
];
|
'status',
|
||||||
|
'trip_type'
|
||||||
|
];
|
||||||
|
|
||||||
public function airline()
|
public function airline()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Airline::class);
|
return $this->belongsTo(Airline::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function airport()
|
public function origin_airport()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Airport::class, 'destination_airport_id');
|
return $this->belongsTo(Airport::class, 'origin_airport_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function bookings()
|
public function airport()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Booking::class);
|
return $this->belongsTo(Airport::class, 'destination_airport_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tours()
|
public function file()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Tour::class, 'file_id');
|
return $this->belongsTo(File::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function bookings()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Booking::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tours()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Tour::class, 'file_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user