refactor: update models relations

This commit is contained in:
2026-08-16 17:00:01 +03:30
parent bd0e1aab31
commit a226931a77
5 changed files with 56 additions and 21 deletions
+9 -2
View File
@@ -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);
+15 -5
View File
@@ -15,12 +15,12 @@ use Illuminate\Database\Eloquent\Model;
*
* @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
@@ -31,17 +31,27 @@ class Airport extends Model
public static $snakeAttributes = false;
protected $casts = [
'city_id' => 'int',
'status' => 'int'
];
protected $fillable = [
'name',
'city',
'country',
'city_id',
'status'
];
public function flights()
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');
}
+6
View File
@@ -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');
+6
View File
@@ -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');
+6
View File
@@ -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);