feat: complete booking
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Account;
|
||||
|
||||
use App\Enums\BookingStatus;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Flight;
|
||||
use App\Models\Tour;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BookingController extends Controller
|
||||
{
|
||||
public function storeFlight(Flight $flight)
|
||||
{
|
||||
Booking::create([
|
||||
'user_id' => 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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user