From b56c9de4ce73189837963bd2ea5d49c8f88b07ee Mon Sep 17 00:00:00 2001 From: Admin Date: Tue, 18 Aug 2026 16:23:36 -0700 Subject: [PATCH] feat: complete booking --- .../Controllers/Account/BookingController.php | 60 ++++++++++++ app/Models/Booking.php | 96 +++++++------------ 2 files changed, 95 insertions(+), 61 deletions(-) create mode 100644 app/Http/Controllers/Account/BookingController.php diff --git a/app/Http/Controllers/Account/BookingController.php b/app/Http/Controllers/Account/BookingController.php new file mode 100644 index 0000000..1f723ff --- /dev/null +++ b/app/Http/Controllers/Account/BookingController.php @@ -0,0 +1,60 @@ + auth()->id(), + 'flight_id' => $flight->id, + 'tour_id' => null, + 'tracking_code' => strtoupper(Str::random(10)), + 'status' => BookingStatus::PENDING, + 'created_at' => now(), + ]); + + return redirect() + ->route('account.booking') + ->with('success', 'پرواز با موفقیت رزرو شد.'); + } + + public function storeTour(Tour $tour) + { + Booking::create([ + 'user_id' => auth()->id(), + 'flight_id' => null, + 'tour_id' => $tour->id, + 'tracking_code' => strtoupper(Str::random(10)), + 'status' => BookingStatus::PENDING, + 'created_at' => now(), + ]); + + return redirect() + ->route('account.booking') + ->with('success', 'تور با موفقیت رزرو شد.'); + } + + public function index() + { + $bookings = Booking::with([ + 'flight.airline', + 'flight.departureAirport.city', + 'flight.arrivalAirport.city', + 'tour', + ]) + ->where('user_id', auth()->id()) + ->latest('created_at') + ->paginate(15); + + return view('account.booking', compact('bookings')); + } +} diff --git a/app/Models/Booking.php b/app/Models/Booking.php index 2337d94..27ead49 100644 --- a/app/Models/Booking.php +++ b/app/Models/Booking.php @@ -1,79 +1,53 @@ 'int', - 'flight_id' => 'int', - 'toure_date_id' => 'int', - 'adult_count' => 'int', - 'child_count' => 'int', - 'total_price' => 'int', + public $timestamps = false; + + protected $casts = [ + 'user_id' => 'int', + 'flight_id' => 'int', + 'tour_id' => 'int', + 'adult_count' => 'int', + 'child_count' => 'int', + 'total_price' => 'int', 'status' => BookingStatus::class, - 'created_at' => 'datetime' - ]; + 'created_at' => 'datetime', + ]; - protected $fillable = [ - 'user_id', - 'flight_id', - 'toure_date_id', - 'adult_count', - 'child_count', - 'total_price', - 'tracking_code', - 'status', - 'created_at', - 'updated_at' - ]; + protected $fillable = [ + 'user_id', + 'flight_id', + 'tour_id', + 'adult_count', + 'child_count', + 'total_price', + 'tracking_code', + 'status', + 'created_at', + ]; - public function flight() - { - return $this->belongsTo(Flight::class); - } + public function flight() + { + return $this->belongsTo(Flight::class); + } - public function tour_date() - { - return $this->belongsTo(TourDate::class, 'toure_date_id'); - } + public function tour() + { + return $this->belongsTo(Tour::class, 'tour_id'); + } - public function user() - { - return $this->belongsTo(User::class); - } + public function user() + { + return $this->belongsTo(User::class); + } public function passengers() {