API: Create a New Booking

Request

Create a new booking with a POST request:

POST /bookings

Request Body:


{
  "mobile": "01712345678",
  "name": "John Doe",
  "gender": "Male",
  "age": 30,
  "address": "123 Main Street, Dhaka",
  "passport_no": null,
  "nid": "1234567890123",
  "nationality": "Bangladeshi",
  "email": "john@example.com",
  "trip_id": 1,
  "type": 2,
  "date": "2025-08-18",
  "time": "10:00:00",
  "route_id": 1,
  "boarding_id": 1,
  "dropping_id": 2,
  "booking_details": [
    {
      "seat_inventory_id": 1,
      "seat_id": 1,
      "price": 1500,
      "discount": 50
    },
    {
      "seat_inventory_id": 2,
      "seat_id": 2,
      "price": 1500,
      "discount": 0
    }
  ]
}
                

Sample Response (201 Created):


{
  "status": "success",
  "code": 201,
  "message": "Booking created successfully and seats marked as sold",
  "data": {
    "booking": {
      "id": 5,
      "pnr_number": "L2DB92GFBG",
      "trip_id": 1,
      "type": 2,
      "date": "2025-08-18",
      "time": "10:00:00",
      "route_id": 1,
      "boarding_id": 1,
      "dropping_id": 2,
      "total_tickets": 2,
      "total_price": 3000,
      "total_discount": 50,
      "total_amount": 2950,
      "status": "confirmed",
      "created_at": "2025-08-18T10:30:00.000000Z"
    },
    "customer": {
      "id": 1,
      "name": "John Doe",
      "mobile": "01712345678",
      "email": "john@example.com",
      "gender": "Male",
      "age": 30,
      "address": "123 Main Street, Dhaka",
      "passport_no": null,
      "nid": "1234567890123",
      "nationality": "Bangladeshi"
    },
    "boarding_info": {
      "id": 1,
      "trip_id": 1,
      "time": "08:00:00",
      "counter_id": 1,
      "counter_name": "Kallyanpur Counter",
      "counter_location": "Near Kallyanpur Bus Stand",
      "district_name": "Dhaka"
    },
    "dropping_info": {
      "id": 2,
      "trip_id": 1,
      "time": "14:00:00",
      "counter_id": 2,
      "counter_name": "GEC Counter",
      "counter_location": "GEC Circle",
      "district_name": "Chittagong"
    },
    "trip_details": {
      "trip_id": 1,
      "trip_date": "2025-08-18",
      "status": 1,
      "coach_type": 1,
      "coach_type_name": "AC",
      "coach": {
        "id": 1,
        "coach_no": "101",
        "status": 1
      },
      "bus": {
        "id": 1,
        "registration_number": "DH-123456",
        "manufacturer_company": "Volvo",
        "model_year": 2020
      },
      "route": {
        "id": 1,
        "start_id": 1,
        "end_id": 2,
        "distance": 264,
        "duration": "06:00"
      },
      "schedule": {
        "id": 1,
        "name": "10:00"
      },
      "seat_plan": {
        "id": 1,
        "name": "AC Business",
        "floor": 1,
        "rows": 10,
        "cols": 4
      }
    },
    "sold_seats": [
      {
        "seat_inventory_id": 1,
        "seat_id": 1,
        "seat_number": "A1",
        "row_position": 1,
        "col_position": 1,
        "seat_type": "window",
        "price": 1500,
        "discount": 50,
        "amount": 1450,
        "status": "sold"
      },
      {
        "seat_inventory_id": 2,
        "seat_id": 2,
        "seat_number": "A2",
        "row_position": 1,
        "col_position": 2,
        "seat_type": "middle",
        "price": 1500,
        "discount": 0,
        "amount": 1500,
        "status": "sold"
      }
    ],
    "seat_status_summary": {
      "total_seats_sold": 2,
      "seat_status": "sold",
      "payment_status": "completed"
    }
  }
}
                

Validation Rules:

  • mobile - Required, string, max:20
  • name - Required, string, max:255
  • gender - Nullable, string, max:255
  • age - Nullable, numeric
  • address - Nullable, string, max:255
  • passport_no - Nullable, string, max:255
  • nid - Nullable, string, max:50
  • nationality - Nullable, string, max:255
  • email - Nullable, string, max:255
  • trip_id - Required, integer
  • type - Required, integer (2=Booked, 3=Blocked, 4=Sold)
  • date - Required, date format: Y-m-d
  • time - Required, time format: H:i:s
  • route_id - Required, integer, must exist in routes table
  • boarding_id - Nullable, integer, must exist in trip_boarding_droppings table
  • dropping_id - Nullable, integer, must exist in trip_boarding_droppings table
  • booking_details - Required, array
  • booking_details.*.seat_inventory_id - Required, integer
  • booking_details.*.seat_id - Required, integer, must exist in seats table
  • booking_details.*.price - Required, numeric
  • booking_details.*.discount - Nullable, numeric

Booking Types:

  • Type 2 (Booked) - Regular booking with payment pending
  • Type 3 (Blocked) - Temporarily blocked for 5 minutes
  • Type 4 (Sold) - Confirmed booking with payment completed

Key Features:

  • Customer Management - Creates or updates customer based on mobile number
  • PNR Generation - Automatically generates unique PNR number
  • Seat Inventory Update - Marks selected seats as sold/booked
  • Multi-seat Booking - Supports booking multiple seats in one transaction
  • Comprehensive Response - Returns complete trip, customer, and seat details
  • Boarding/Dropping Points - Includes counter and location information

Notes:

  • The system automatically finds or creates a customer based on the mobile number
  • All selected seats must be available for booking
  • PNR numbers are unique alphanumeric codes
  • Booking details array allows multiple seats to be booked simultaneously
  • Response includes complete trip information and boarding/dropping point details