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'));
|
||||||
|
}
|
||||||
|
}
|
||||||
+35
-61
@@ -1,79 +1,53 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Reliese Model.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Enums\BookingStatus;
|
use App\Enums\BookingStatus;
|
||||||
use Carbon\Carbon;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Booking
|
|
||||||
*
|
|
||||||
* @property int $id
|
|
||||||
* @property int $user_id
|
|
||||||
* @property int $flight_id
|
|
||||||
* @property int $toure_date_id
|
|
||||||
* @property int $adult_count
|
|
||||||
* @property int $child_count
|
|
||||||
* @property int $total_price
|
|
||||||
* @property string $tracking_code
|
|
||||||
* @property int $status
|
|
||||||
* @property Carbon $created_ar
|
|
||||||
* @property Carbon $updated_at
|
|
||||||
*
|
|
||||||
* @property Flight $flights
|
|
||||||
* @property TourDate $tour_date
|
|
||||||
* @property User $user
|
|
||||||
*
|
|
||||||
* @package App\Models
|
|
||||||
*/
|
|
||||||
class Booking extends Model
|
class Booking extends Model
|
||||||
{
|
{
|
||||||
protected $table = 'bookings';
|
protected $table = 'bookings';
|
||||||
public $timestamps = false;
|
|
||||||
|
|
||||||
protected $casts = [
|
public $timestamps = false;
|
||||||
'user_id' => 'int',
|
|
||||||
'flight_id' => 'int',
|
protected $casts = [
|
||||||
'toure_date_id' => 'int',
|
'user_id' => 'int',
|
||||||
'adult_count' => 'int',
|
'flight_id' => 'int',
|
||||||
'child_count' => 'int',
|
'tour_id' => 'int',
|
||||||
'total_price' => 'int',
|
'adult_count' => 'int',
|
||||||
|
'child_count' => 'int',
|
||||||
|
'total_price' => 'int',
|
||||||
'status' => BookingStatus::class,
|
'status' => BookingStatus::class,
|
||||||
'created_at' => 'datetime'
|
'created_at' => 'datetime',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'user_id',
|
'user_id',
|
||||||
'flight_id',
|
'flight_id',
|
||||||
'toure_date_id',
|
'tour_id',
|
||||||
'adult_count',
|
'adult_count',
|
||||||
'child_count',
|
'child_count',
|
||||||
'total_price',
|
'total_price',
|
||||||
'tracking_code',
|
'tracking_code',
|
||||||
'status',
|
'status',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at'
|
];
|
||||||
];
|
|
||||||
|
|
||||||
public function flight()
|
public function flight()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Flight::class);
|
return $this->belongsTo(Flight::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tour_date()
|
public function tour()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(TourDate::class, 'toure_date_id');
|
return $this->belongsTo(Tour::class, 'tour_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function user()
|
public function user()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function passengers()
|
public function passengers()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user