From 571c9334763b8e86e86dcce2750d0790aa75d7cf Mon Sep 17 00:00:00 2001 From: Admin Date: Mon, 17 Aug 2026 13:13:45 -0700 Subject: [PATCH] fix:edit models --- app/Models/Airport.php | 15 +++++++++++++-- app/Models/Booking.php | 19 +++++++++++++------ app/Models/BookingPassenger.php | 15 +++++++++++---- app/Models/Tour.php | 16 +++++++++++----- app/Models/User.php | 9 ++++++--- 5 files changed, 54 insertions(+), 20 deletions(-) diff --git a/app/Models/Airport.php b/app/Models/Airport.php index 9c31503..bd2e49b 100644 --- a/app/Models/Airport.php +++ b/app/Models/Airport.php @@ -14,10 +14,11 @@ use Illuminate\Database\Eloquent\Model; * * @property int $id * @property string $name - * @property string $city + * @property int $city_id * @property string $country * @property string $code * + * @property City $city * @property Collection|Flight[] $flights * * @package App\Models @@ -26,14 +27,24 @@ class Airport extends Model { protected $table = 'airports'; public $timestamps = false; + public static $snakeAttributes = false; + + protected $casts = [ + 'city_id' => 'int' + ]; protected $fillable = [ 'name', - 'city', + 'city_id', 'country', 'code' ]; + public function city() + { + return $this->belongsTo(City::class); + } + public function flights() { return $this->hasMany(Flight::class, 'departure_airport_id'); diff --git a/app/Models/Booking.php b/app/Models/Booking.php index 3a4a62f..2337d94 100644 --- a/app/Models/Booking.php +++ b/app/Models/Booking.php @@ -6,12 +6,13 @@ namespace App\Models; +use App\Enums\BookingStatus; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; /** * Class Booking - * + * * @property int $id * @property int $user_id * @property int $flight_id @@ -23,8 +24,8 @@ use Illuminate\Database\Eloquent\Model; * @property int $status * @property Carbon $created_ar * @property Carbon $updated_at - * - * @property Flight $flight + * + * @property Flight $flights * @property TourDate $tour_date * @property User $user * @@ -42,8 +43,8 @@ class Booking extends Model 'adult_count' => 'int', 'child_count' => 'int', 'total_price' => 'int', - 'status' => 'int', - 'created_ar' => 'datetime' + 'status' => BookingStatus::class, + 'created_at' => 'datetime' ]; protected $fillable = [ @@ -55,7 +56,8 @@ class Booking extends Model 'total_price', 'tracking_code', 'status', - 'created_ar' + 'created_at', + 'updated_at' ]; public function flight() @@ -72,4 +74,9 @@ class Booking extends Model { return $this->belongsTo(User::class); } + + public function passengers() + { + return $this->hasMany(BookingPassenger::class); + } } diff --git a/app/Models/BookingPassenger.php b/app/Models/BookingPassenger.php index 656ccaf..6616058 100644 --- a/app/Models/BookingPassenger.php +++ b/app/Models/BookingPassenger.php @@ -6,12 +6,13 @@ namespace App\Models; +use App\Enums\PassengerType; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; /** * Class BookingPassenger - * + * * @property int $id * @property int $booking_id * @property string $first_name @@ -32,8 +33,8 @@ class BookingPassenger extends Model protected $casts = [ 'booking_id' => 'int', 'birth_date' => 'datetime', - 'passenger_type' => 'int', - 'created_ar' => 'datetime' + 'passenger_type' => PassengerType::class, + 'created_at' => 'datetime' ]; protected $fillable = [ @@ -43,6 +44,12 @@ class BookingPassenger extends Model 'national_code', 'birth_date', 'passenger_type', - 'created_ar' + 'created_at', + 'updated_at' ]; + + public function booking() + { + return $this->belongsTo(Booking::class); + } } diff --git a/app/Models/Tour.php b/app/Models/Tour.php index 85003ac..0d6dd41 100644 --- a/app/Models/Tour.php +++ b/app/Models/Tour.php @@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\Model; /** * Class Tour - * + * * @property int $id * @property string $title * @property string $summary @@ -22,9 +22,9 @@ use Illuminate\Database\Eloquent\Model; * @property int|null $file_id * @property int $duration * @property int $status - * @property Carbon $created_ar + * @property Carbon $created_at * @property Carbon $updated_at - * + * * @property File|null $file * @property Collection|TourDate[] $tour_dates * @@ -38,8 +38,9 @@ class Tour extends Model protected $casts = [ 'file_id' => 'int', 'duration' => 'int', + 'views' => 'int', 'status' => 'int', - 'created_ar' => 'datetime' + 'created_at' => 'datetime' ]; protected $fillable = [ @@ -50,8 +51,9 @@ class Tour extends Model 'destination', 'file_id', 'duration', + 'views', 'status', - 'created_ar' + 'created_at' ]; public function file() @@ -63,4 +65,8 @@ class Tour extends Model { return $this->hasMany(TourDate::class); } + public function comments() + { + return $this->hasMany(Comment::class, 'tour_id'); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 1988879..6f3023f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,6 +6,9 @@ namespace App\Models; +use App\Enums\UserGenderStatus; +use App\Enums\UserMaritalStatus; +use App\Enums\UserStatus; use Carbon\Carbon; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; @@ -47,12 +50,12 @@ class User extends Authenticated public static $snakeAttributes = false; protected $casts = [ - 'gender' => 'int', - 'marital_status' => 'int', + 'gender' => UserGenderStatus::class, + 'marital_status' => UserMaritalStatus::class, 'file_id' => 'int', 'province_id' => 'int', 'city_id' => 'int', - 'status' => 'int', + 'status' => UserStatus::class, 'deleted' => 'datetime' ];