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 int $id
* @property string $name * @property string $name
* @property string $country * @property int $country_id
* @property string $phone * @property string $phone
* @property int $status * @property int $status
* @property Carbon $created_at * @property Carbon $created_at
* @property Carbon $updated_at * @property Carbon $updated_at
* *
* @property Country $country
* @property Collection|Flight[] $flights * @property Collection|Flight[] $flights
* *
* @package App\Models * @package App\Models
@@ -31,16 +32,22 @@ class Airline extends Model
public static $snakeAttributes = false; public static $snakeAttributes = false;
protected $casts = [ protected $casts = [
'country_id' => 'int',
'status' => 'int' 'status' => 'int'
]; ];
protected $fillable = [ protected $fillable = [
'name', 'name',
'country', 'country_id',
'phone', 'phone',
'status' 'status'
]; ];
public function country()
{
return $this->belongsTo(Country::class);
}
public function flights() public function flights()
{ {
return $this->hasMany(Flight::class); return $this->hasMany(Flight::class);
+27 -17
View File
@@ -15,34 +15,44 @@ use Illuminate\Database\Eloquent\Model;
* *
* @property int $id * @property int $id
* @property string $name * @property string $name
* @property string $city * @property int $city_id
* @property string $country
* @property int $status * @property int $status
* @property Carbon $created_at * @property Carbon $created_at
* @property Carbon $updated_at * @property Carbon $updated_at
* *
* @property City $city
* @property Collection|Flight[] $flights * @property Collection|Flight[] $flights
* *
* @package App\Models * @package App\Models
*/ */
class Airport extends Model class Airport extends Model
{ {
protected $table = 'airports'; protected $table = 'airports';
public static $snakeAttributes = false; public static $snakeAttributes = false;
protected $casts = [ protected $casts = [
'status' => 'int' 'city_id' => 'int',
]; 'status' => 'int'
];
protected $fillable = [ protected $fillable = [
'name', 'name',
'city', 'city_id',
'country', 'status'
'status' ];
];
public function flights() public function city()
{ {
return $this->hasMany(Flight::class, 'destination_airport_id'); 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 Country $country
* @property Province $province * @property Province $province
* @property Collection|Airport[] $airports
* @property Collection|Tour[] $tours * @property Collection|Tour[] $tours
* @property Collection|User[] $users * @property Collection|User[] $users
* *
@@ -59,6 +60,11 @@ class City extends Model
return $this->belongsTo(Province::class); return $this->belongsTo(Province::class);
} }
public function airports()
{
return $this->hasMany(Airport::class);
}
public function tours() public function tours()
{ {
return $this->hasMany(Tour::class, 'destination_city_id'); 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 Carbon $updated_at
* @property string|null $deleted_at * @property string|null $deleted_at
* *
* @property Collection|Airline[] $airlines
* @property Collection|City[] $cities * @property Collection|City[] $cities
* *
* @package App\Models * @package App\Models
@@ -40,6 +41,11 @@ class Country extends Model
'status' 'status'
]; ];
public function airlines()
{
return $this->hasMany(Airline::class);
}
public function cities() public function cities()
{ {
return $this->hasMany(City::class, 'county_id'); 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 $created_at
* @property Carbon $updated_at * @property Carbon $updated_at
* *
* @property Collection|Flight[] $flights
* @property Collection|User[] $users * @property Collection|User[] $users
* *
* @package App\Models * @package App\Models
@@ -43,6 +44,11 @@ class File extends Model
'path' 'path'
]; ];
public function flights()
{
return $this->hasMany(Flight::class);
}
public function users() public function users()
{ {
return $this->hasMany(User::class); return $this->hasMany(User::class);