API: Search Trips

Request

Search for available trips with a GET request:

GET /search-trips

Required Query Parameters:

  • trip_date - Date of the trip (YYYY-MM-DD format)
  • route_start_id - Starting district/location ID
  • route_end_id - Ending district/location ID

Optional Query Parameters:

  • coach_no - Filter by specific coach number
  • schedule_id - Filter by specific schedule ID
  • coach_type - Filter by specific coach type (only accept: 1 for AC, 2 for Non-AC)
  • boarding_counter_id - Filter by specific boarding counter (only accept existing counter ID)
  • dropping_counter_id - Filter by specific dropping counter (only accept existing counter ID)
  • page - Page number for pagination (default: 1)
  • per_page - Items per page (default: 15)

Sample Request:

GET /search-trips?trip_date=2025-08-18&route_start_id=2&route_end_id=2&coach_no=101&schedule_id=1

Sample Response:


{
  "status": "success",
  "code": 200,
  "message": "Active trips retrieved successfully",
  "data": {
    "trips": {
      "current_page": 1,
      "data": [
        {
          "trip_id": 3,
          "trip_date": "2025-08-18",
          "trip_date_formatted": "Monday, August 18, 2025",
          "status": 1,
          "status_name": "Active",
          "coach_type": 1,
          "coach_type_name": "AC",
          "current_partition": "trip_instances_202508",
          "coach_id": 2,
          "coach_no": "101",
          "coach_seat_plan_id": 1,
          "coach_status": 1,
          "bus_id": 1,
          "bus_registration_number": "123",
          "bus_manufacturer": "ad",
          "bus_model_year": 2000,
          "schedule_id": 1,
          "schedule_name": "11:00",
          "route_id": 1,
          "start_id": 2,
          "end_id": 2,
          "distance": 1300,
          "duration": "02:45",
          "start_district_name": "Updated District 1",
          "end_district_name": "Updated District 1",
          "route_display": "Updated District 1 → Updated District 1",
          "driver_id": null,
          "driver_name": null,
          "driver_contact": null,
          "driver_license": null,
          "supervisor_id": null,
          "supervisor_name": null,
          "supervisor_contact": null,
          "seat_plan_id": 1,
          "seat_plan_name": "Bus A",
          "seat_plan_floors": null,
          "seat_plan_rows": 6,
          "seat_plan_cols": 4,
          "total_seats": 0,
          "seat_inventory_summary": {
            "total_seats": 0,
            "available_seats": 0,
            "booked_seats": 0,
            "blocked_seats": 0,
            "occupancy_percentage": 0,
            "has_inventory": true
          },
          "is_ac": true,
          "is_active": true,
          "is_migrated": false,
          "created_at": "2025-08-14T10:22:04.000000Z",
          "updated_at": "2025-08-14T10:22:04.000000Z"
        }
      ],
      "first_page_url": "http://127.0.0.1:8000/api/search-trips?page=1",
      "from": 1,
      "last_page": 1,
      "last_page_url": "http://127.0.0.1:8000/api/search-trips?page=1",
      "links": [
        {
          "url": null,
          "label": "« Previous",
          "active": false
        },
        {
          "url": "http://127.0.0.1:8000/api/search-trips?page=1",
          "label": "1",
          "active": true
        },
        {
          "url": null,
          "label": "Next »",
          "active": false
        }
      ],
      "next_page_url": null,
      "path": "http://127.0.0.1:8000/api/search-trips",
      "per_page": 15,
      "prev_page_url": null,
      "to": 1,
      "total": 1
    },
    "search_criteria": {
      "trip_date": "2025-08-18",
      "route_start_id": 2,
      "route_end_id": 2,
      "coach_no": null,
      "schedule_id": null
    },
    "total_trips": 1,
    "boarding_counters": [
        {
            "id": 1,
            "type": "1",
            "address": "Dhaka",
            "land_mark": null,
            "location_url": null,
            "phone": null,
            "mobile": null,
            "email": null,
            "primary_contact_no": null,
            "country": null,
            "district_id": 1,
            "booking_allowed_status": "1",
            "booking_allowed_class": "1",
            "no_of_boarding_allowed": null,
            "sms_status": "1",
            "status": "1",
            "created_by": 1,
            "updated_by": null,
            "created_at": "2025-09-03T14:23:13.000000Z",
            "updated_at": null,
            "deleted_at": null
        }
    ],
    "dropping_counters": [
        {
            "id": 2,
            "type": "1",
            "address": "Chittagong",
            "land_mark": null,
            "location_url": null,
            "phone": null,
            "mobile": null,
            "email": null,
            "primary_contact_no": null,
            "country": null,
            "district_id": 2,
            "booking_allowed_status": "1",
            "booking_allowed_class": "1",
            "no_of_boarding_allowed": null,
            "sms_status": "1",
            "status": "1",
            "created_by": 1,
            "updated_by": null,
            "created_at": "2025-09-03T14:23:13.000000Z",
            "updated_at": null,
            "deleted_at": null
        }
    ]
  }
}
                

Response Structure:

  • trips - Paginated list of matching trips with complete details
  • search_criteria - Echo of the search parameters used
  • total_trips - Total number of trips found matching the criteria

Trip Information Fields:

  • Basic Trip Data - trip_id, trip_date, status, coach_type
  • Coach Information - coach_id, coach_no, coach_status
  • Bus Details - bus_registration_number, bus_manufacturer, bus_model_year
  • Schedule - schedule_id, schedule_name (departure time)
  • Route Details - start/end districts, distance, duration, route_display
  • Staff - driver and supervisor information (if assigned)
  • Seat Plan - seat_plan_name, rows, cols, total_seats
  • Seat Inventory Summary - available, booked, blocked seats and occupancy percentage

Coach Types:

  • 1 (AC) - Air-conditioned coach
  • 2 (Non-AC) - Non air-conditioned coach

Status Values:

  • 1 (Active) - Trip is active and available for booking
  • 0 (Inactive) - Trip is inactive

Seat Inventory Summary:

  • total_seats - Total seats in the coach
  • available_seats - Seats available for booking
  • booked_seats - Seats already booked
  • blocked_seats - Seats temporarily blocked
  • occupancy_percentage - Percentage of seats occupied
  • has_inventory - Whether seat inventory exists for this trip

Pagination:

The response includes standard Laravel pagination with links, page numbers, and navigation URLs for easy frontend implementation.

Partition Information:

The current_partition field shows which database partition is being used for the trip data, formatted as "trip_instances_YYYYMM".

Use Cases:

  • Trip Booking - Find available trips for passengers
  • Route Planning - Search trips between specific locations
  • Schedule Management - Filter trips by specific schedules
  • Fleet Management - Search trips by coach number
  • Availability Check - Check seat availability and occupancy

Error Responses:

400 Bad Request - Missing Required Parameters

{
  "status": "error",
  "code": 400,
  "message": "Required parameters missing",
  "errors": {
    "trip_date": ["Trip date is required"],
    "route_start_id": ["Start location is required"],
    "route_end_id": ["End location is required"]
  }
}
                
404 Not Found - No Trips Available

{
  "status": "success",
  "code": 200,
  "message": "No trips found matching the criteria",
  "data": {
    "trips": {
      "current_page": 1,
      "data": [],
      "total": 0
    },
    "search_criteria": {
      "trip_date": "2025-08-18",
      "route_start_id": 2,
      "route_end_id": 3
    },
    "total_trips": 0
  }
}