feat: add booking management
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Flight;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class BookingController extends Controller
|
||||||
|
{
|
||||||
|
public function flight(Flight $flight)
|
||||||
|
{
|
||||||
|
// فقط پرواز فعال
|
||||||
|
if ((int)$flight->status !== 1) {
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
$flight->load([
|
||||||
|
'travelType',
|
||||||
|
'origin',
|
||||||
|
'destination',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return view('account.bookings', compact('flight'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function storeFlight(Request $request, Flight $flight)
|
||||||
|
{
|
||||||
|
// بررسی فعال بودن پرواز
|
||||||
|
if ((int) $flight->status !== 1) {
|
||||||
|
abort(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// اعتبارسنجی
|
||||||
|
$validated = $request->validate([
|
||||||
|
'first_name' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'max:100',
|
||||||
|
],
|
||||||
|
|
||||||
|
'last_name' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'max:100',
|
||||||
|
],
|
||||||
|
|
||||||
|
'national_code' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'max:20',
|
||||||
|
],
|
||||||
|
|
||||||
|
'phone' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'max:20',
|
||||||
|
],
|
||||||
|
|
||||||
|
'passengers' => [
|
||||||
|
'required',
|
||||||
|
'integer',
|
||||||
|
'min:1',
|
||||||
|
'max:10',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
// فعلاً برای تست
|
||||||
|
return redirect()
|
||||||
|
->route('flights.show', $flight)
|
||||||
|
->with(
|
||||||
|
'success',
|
||||||
|
'درخواست رزرو پرواز با موفقیت ثبت شد.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Reliese Model.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Booking
|
||||||
|
*
|
||||||
|
* @property int $id
|
||||||
|
* @property int $user_id
|
||||||
|
* @property int|null $tour_id
|
||||||
|
* @property int|null $flight_id
|
||||||
|
* @property string $booking_code
|
||||||
|
* @property string $first_name
|
||||||
|
* @property string $last_name
|
||||||
|
* @property string|null $national_code
|
||||||
|
* @property string $mobile
|
||||||
|
* @property string|null $email
|
||||||
|
* @property int $passengers
|
||||||
|
* @property float $price
|
||||||
|
* @property int $status
|
||||||
|
* @property string $payment_status
|
||||||
|
* @property string|null $notes
|
||||||
|
* @property Carbon $created_at
|
||||||
|
* @property Carbon $updated_at
|
||||||
|
*
|
||||||
|
* @property User $user
|
||||||
|
* @property Tour|null $tour
|
||||||
|
* @property Flight|null $flight
|
||||||
|
*
|
||||||
|
* @package App\Models
|
||||||
|
*/
|
||||||
|
class Booking extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'bookings';
|
||||||
|
public static $snakeAttributes = false;
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'user_id' => 'int',
|
||||||
|
'tour_id' => 'int',
|
||||||
|
'flight_id' => 'int',
|
||||||
|
'passengers' => 'int',
|
||||||
|
'price' => 'float',
|
||||||
|
'status' => 'int'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'user_id',
|
||||||
|
'tour_id',
|
||||||
|
'flight_id',
|
||||||
|
'booking_code',
|
||||||
|
'first_name',
|
||||||
|
'last_name',
|
||||||
|
'national_code',
|
||||||
|
'mobile',
|
||||||
|
'email',
|
||||||
|
'passengers',
|
||||||
|
'price',
|
||||||
|
'status',
|
||||||
|
'payment_status',
|
||||||
|
'notes'
|
||||||
|
];
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tour()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Tour::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function flight()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Flight::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,202 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
|
||||||
|
<div class="container" style="padding: 50px 0;">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
<div class="col-md-8 col-md-offset-2">
|
||||||
|
|
||||||
|
<div class="panel panel-default">
|
||||||
|
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3>
|
||||||
|
رزرو پرواز
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="panel-body">
|
||||||
|
|
||||||
|
{{-- اطلاعات پرواز --}}
|
||||||
|
|
||||||
|
<div class="flight-booking-info">
|
||||||
|
|
||||||
|
<h3>
|
||||||
|
{{ $flight->title }}
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>
|
||||||
|
شماره پرواز:
|
||||||
|
</strong>
|
||||||
|
|
||||||
|
{{ $flight->flight_number ?? '-' }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>
|
||||||
|
مبدا:
|
||||||
|
</strong>
|
||||||
|
|
||||||
|
{{ $flight->origin->name ?? $flight->origin ?? '-' }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>
|
||||||
|
مقصد:
|
||||||
|
</strong>
|
||||||
|
|
||||||
|
{{ $flight->destination->name ?? $flight->destination ?? '-' }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>
|
||||||
|
تاریخ حرکت:
|
||||||
|
</strong>
|
||||||
|
|
||||||
|
{{ $flight->departure_date ?? '-' }}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>
|
||||||
|
قیمت:
|
||||||
|
</strong>
|
||||||
|
|
||||||
|
{{ number_format($flight->price ?? 0) }}
|
||||||
|
|
||||||
|
تومان
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
|
||||||
|
{{-- فرم رزرو --}}
|
||||||
|
|
||||||
|
<form
|
||||||
|
action="{{ route('booking.flight.store', $flight) }}"
|
||||||
|
method="POST"
|
||||||
|
>
|
||||||
|
|
||||||
|
@csrf
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
|
||||||
|
<label>
|
||||||
|
نام مسافر
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="first_name"
|
||||||
|
class="form-control"
|
||||||
|
value="{{ old('first_name') }}"
|
||||||
|
required
|
||||||
|
>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
|
||||||
|
<label>
|
||||||
|
نام خانوادگی
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="last_name"
|
||||||
|
class="form-control"
|
||||||
|
value="{{ old('last_name') }}"
|
||||||
|
required
|
||||||
|
>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
|
||||||
|
<label>
|
||||||
|
کد ملی
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="national_code"
|
||||||
|
class="form-control"
|
||||||
|
value="{{ old('national_code') }}"
|
||||||
|
required
|
||||||
|
>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
|
||||||
|
<label>
|
||||||
|
شماره موبایل
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="phone"
|
||||||
|
class="form-control"
|
||||||
|
value="{{ old('phone') }}"
|
||||||
|
required
|
||||||
|
>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
|
||||||
|
<label>
|
||||||
|
تعداد مسافر
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
name="passengers"
|
||||||
|
class="form-control"
|
||||||
|
value="{{ old('passengers', 1) }}"
|
||||||
|
min="1"
|
||||||
|
max="10"
|
||||||
|
required
|
||||||
|
>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
class="btn btn-success btn-lg"
|
||||||
|
>
|
||||||
|
ثبت رزرو
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<a
|
||||||
|
href="{{ route('flights.show', $flight) }}"
|
||||||
|
class="btn btn-default btn-lg"
|
||||||
|
>
|
||||||
|
بازگشت
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@endsection
|
||||||
Reference in New Issue
Block a user