diff --git a/app/Models/Airline.php b/app/Models/Airline.php index 5282252..300fa86 100644 --- a/app/Models/Airline.php +++ b/app/Models/Airline.php @@ -15,12 +15,13 @@ use Illuminate\Database\Eloquent\Model; * * @property int $id * @property string $name - * @property string $country + * @property int $country_id * @property string $phone * @property int $status * @property Carbon $created_at * @property Carbon $updated_at * + * @property Country $country * @property Collection|Flight[] $flights * * @package App\Models @@ -31,16 +32,22 @@ class Airline extends Model public static $snakeAttributes = false; protected $casts = [ + 'country_id' => 'int', 'status' => 'int' ]; protected $fillable = [ 'name', - 'country', + 'country_id', 'phone', 'status' ]; + public function country() + { + return $this->belongsTo(Country::class); + } + public function flights() { return $this->hasMany(Flight::class); diff --git a/app/Models/Airport.php b/app/Models/Airport.php index 0ada8ec..0129a70 100644 --- a/app/Models/Airport.php +++ b/app/Models/Airport.php @@ -12,37 +12,47 @@ use Illuminate\Database\Eloquent\Model; /** * Class Airport - * + * * @property int $id * @property string $name - * @property string $city - * @property string $country + * @property int $city_id * @property int $status * @property Carbon $created_at * @property Carbon $updated_at - * + * + * @property City $city * @property Collection|Flight[] $flights * * @package App\Models */ class Airport extends Model { - protected $table = 'airports'; - public static $snakeAttributes = false; + protected $table = 'airports'; + public static $snakeAttributes = false; - protected $casts = [ - 'status' => 'int' - ]; + protected $casts = [ + 'city_id' => 'int', + 'status' => 'int' + ]; - protected $fillable = [ - 'name', - 'city', - 'country', - 'status' - ]; + protected $fillable = [ + 'name', + 'city_id', + 'status' + ]; - public function flights() - { - return $this->hasMany(Flight::class, 'destination_airport_id'); - } + public function city() + { + return $this->belongsTo(City::class); + } + + public function originFlights() + { + return $this->hasMany(Flight::class, 'origin_airport_id'); + } + + public function destinationFlights() + { + return $this->hasMany(Flight::class, 'destination_airport_id'); + } } diff --git a/app/Models/City.php b/app/Models/City.php index e5ddc35..c204b7c 100644 --- a/app/Models/City.php +++ b/app/Models/City.php @@ -25,6 +25,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * * @property Country $country * @property Province $province + * @property Collection|Airport[] $airports * @property Collection|Tour[] $tours * @property Collection|User[] $users * @@ -59,6 +60,11 @@ class City extends Model return $this->belongsTo(Province::class); } + public function airports() + { + return $this->hasMany(Airport::class); + } + public function tours() { return $this->hasMany(Tour::class, 'destination_city_id'); diff --git a/app/Models/Country.php b/app/Models/Country.php index cdc2112..6e0db02 100644 --- a/app/Models/Country.php +++ b/app/Models/Country.php @@ -21,6 +21,7 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property Carbon $updated_at * @property string|null $deleted_at * + * @property Collection|Airline[] $airlines * @property Collection|City[] $cities * * @package App\Models @@ -40,6 +41,11 @@ class Country extends Model 'status' ]; + public function airlines() + { + return $this->hasMany(Airline::class); + } + public function cities() { return $this->hasMany(City::class, 'county_id'); diff --git a/app/Models/File.php b/app/Models/File.php index a73479a..5f051e0 100644 --- a/app/Models/File.php +++ b/app/Models/File.php @@ -22,6 +22,7 @@ use Illuminate\Database\Eloquent\Model; * @property Carbon $created_at * @property Carbon $updated_at * + * @property Collection|Flight[] $flights * @property Collection|User[] $users * * @package App\Models @@ -43,6 +44,11 @@ class File extends Model 'path' ]; + public function flights() + { + return $this->hasMany(Flight::class); + } + public function users() { return $this->hasMany(User::class);