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;
|
||||
|
||||
use App\Enums\FlightStatus;
|
||||
use App\Enums\FlightTripType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Flight
|
||||
*
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $airline_id
|
||||
* @property int $origin_airport_id
|
||||
* @property int $destination_airport_id
|
||||
* @property int|null $file_id
|
||||
* @property string $flight_number
|
||||
* @property Carbon $departure_time
|
||||
* @property int $price
|
||||
@@ -24,9 +27,10 @@ use Illuminate\Database\Eloquent\Model;
|
||||
* @property int $status
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*
|
||||
*
|
||||
* @property Airline $airline
|
||||
* @property Airport $airport
|
||||
* @property File|null $file
|
||||
* @property Collection|Booking[] $bookings
|
||||
* @property Collection|Tour[] $tours
|
||||
*
|
||||
@@ -34,47 +38,61 @@ use Illuminate\Database\Eloquent\Model;
|
||||
*/
|
||||
class Flight extends Model
|
||||
{
|
||||
protected $table = 'flights';
|
||||
public static $snakeAttributes = false;
|
||||
protected $table = 'flights';
|
||||
public static $snakeAttributes = false;
|
||||
|
||||
protected $casts = [
|
||||
'airline_id' => 'int',
|
||||
'origin_airport_id' => 'int',
|
||||
'destination_airport_id' => 'int',
|
||||
'departure_time' => 'datetime',
|
||||
'price' => 'int',
|
||||
'capacity' => 'int',
|
||||
'status' => 'int'
|
||||
];
|
||||
protected $casts = [
|
||||
'airline_id' => 'int',
|
||||
'origin_airport_id' => 'int',
|
||||
'destination_airport_id' => 'int',
|
||||
'file_id' => 'int',
|
||||
'departure_time' => 'datetime',
|
||||
'price' => 'int',
|
||||
'capacity' => 'int',
|
||||
'status' => FlightStatus::class,
|
||||
'trip_type' => FlightTripType::class
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'airline_id',
|
||||
'origin_airport_id',
|
||||
'destination_airport_id',
|
||||
'flight_number',
|
||||
'departure_time',
|
||||
'price',
|
||||
'capacity',
|
||||
'status'
|
||||
];
|
||||
protected $fillable = [
|
||||
'airline_id',
|
||||
'origin_airport_id',
|
||||
'destination_airport_id',
|
||||
'file_id',
|
||||
'flight_number',
|
||||
'departure_time',
|
||||
'price',
|
||||
'capacity',
|
||||
'status',
|
||||
'trip_type'
|
||||
];
|
||||
|
||||
public function airline()
|
||||
{
|
||||
return $this->belongsTo(Airline::class);
|
||||
}
|
||||
public function airline()
|
||||
{
|
||||
return $this->belongsTo(Airline::class);
|
||||
}
|
||||
|
||||
public function airport()
|
||||
{
|
||||
return $this->belongsTo(Airport::class, 'destination_airport_id');
|
||||
}
|
||||
public function origin_airport()
|
||||
{
|
||||
return $this->belongsTo(Airport::class, 'origin_airport_id');
|
||||
}
|
||||
|
||||
public function bookings()
|
||||
{
|
||||
return $this->hasMany(Booking::class);
|
||||
}
|
||||
public function airport()
|
||||
{
|
||||
return $this->belongsTo(Airport::class, 'destination_airport_id');
|
||||
}
|
||||
|
||||
public function tours()
|
||||
{
|
||||
return $this->hasMany(Tour::class, 'file_id');
|
||||
}
|
||||
public function file()
|
||||
{
|
||||
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