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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user