fix:edit booking controller
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<?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\TourDate;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class BookingController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$bookings = Booking::query()
|
||||
->where('user_id', auth()->id())
|
||||
->with([
|
||||
'flight.departureAirport.city',
|
||||
'flight.arrivalAirport.city',
|
||||
'tourDate.tour',
|
||||
])
|
||||
->orderByDesc('created_at')
|
||||
->paginate(10);
|
||||
|
||||
return view('account.booking', compact('bookings'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'flight_id' => 'nullable|exists:flights,id',
|
||||
'tour_date_id' => 'nullable|exists:tour_dates,id',
|
||||
'adult_count' => 'required|integer|min:1',
|
||||
'child_count' => 'required|integer|min:0',
|
||||
]);
|
||||
|
||||
$totalPrice = 0;
|
||||
|
||||
if ($request->flight_id) {
|
||||
|
||||
$flight = Flight::findOrFail($request->flight_id);
|
||||
|
||||
$totalPrice = $flight->price *
|
||||
($request->adult_count + $request->child_count);
|
||||
|
||||
} elseif ($request->tour_date_id) {
|
||||
|
||||
$tourDate = TourDate::findOrFail($request->tour_date_id);
|
||||
|
||||
$totalPrice = $tourDate->price *
|
||||
($request->adult_count + $request->child_count);
|
||||
}
|
||||
|
||||
$booking = Booking::create([
|
||||
'user_id' => auth()->id(),
|
||||
'flight_id' => $request->flight_id,
|
||||
'tour_date_id' => $request->tour_date_id,
|
||||
'adult_count' => $request->adult_count,
|
||||
'child_count' => $request->child_count,
|
||||
'total_price' => $totalPrice,
|
||||
'tracking_code' => 'BK-' . strtoupper(Str::random(10)),
|
||||
'status' => BookingStatus::PENDING,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return redirect()
|
||||
->route('account.booking')
|
||||
->with('success', 'رزرو شما با موفقیت ثبت شد.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Created by Reliese Model.
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Admin
|
||||
*
|
||||
* @property int $id
|
||||
* @property int|null $file_id
|
||||
* @property string $first_name
|
||||
* @property string $last_name
|
||||
* @property string $email
|
||||
* @property string $password
|
||||
* @property int $status
|
||||
* @property Carbon $created_at
|
||||
* @property Carbon $updated_at
|
||||
*
|
||||
* @package App\Models
|
||||
*/
|
||||
class Admin extends Authenticatable
|
||||
{
|
||||
protected $table = 'admins';
|
||||
public static $snakeAttributes = false;
|
||||
|
||||
protected $casts = [
|
||||
'file_id' => 'int',
|
||||
'status' => 'int'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password'
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'file_id',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
'username',
|
||||
'password',
|
||||
'status'
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user