API: Update Fare

Request

Update the details of a specific fare by ID:

PUT /fares/{id}

Request Body:


{
  "route_id": 2,
  "seat_plan_id": 2,
  "coach_type": 2,
  "seat_type": "Economy",
  "from_date": "2024-02-01",
  "to_date": "2024-11-30",
  "amount": 800,
  "status": 1
}
                

Sample Response:


{
  "status": "success",
  "message": "Fare updated successfully",
  "data": {
    "id": 1,
    "route_id": 2,
    "start_id": 2,
    "end_id": 3,
    "start_name": "Chittagong",
    "end_name": "Sylhet",
    "distance": 189,
    "duration": "4:15",
    "route_status": 1,
    "seat_plan_id": 2,
    "seat_plan_name": "Non-AC",
    "coach_type": 2,
    "seat_type": "Economy",
    "from_date": "2024-02-01",
    "to_date": "2024-11-30",
    "amount": 800,
    "status": 1,
    "created_by": 1,
    "updated_by": 1,
    "created_at": "2024-01-01T12:00:00",
    "updated_at": "2024-01-15T14:30:00",
    "deleted_at": null
  }
}
                

Validation Rules:

  • route_id - Required, must exist in routes table
  • seat_plan_id - Required, must exist in seat_plans table
  • coach_type - Required, integer, must be 1 (AC) or 2 (Non-AC)
  • seat_type - Required, string, must be one of: "Suite Class", "Business Class", "Sleeper", "Economy"
  • from_date - Optional, valid date format
  • to_date - Optional, valid date format, must be after or equal to from_date
  • amount - Required, integer, fare amount in the smallest currency unit
  • status - Optional, integer, must be 0 (inactive) or 1 (active), defaults to 1

Available Seat Types:

  • Suite Class - Premium luxury seating
  • Business Class - Enhanced comfort
  • Sleeper - Long journey comfort
  • Economy - Budget-friendly option

Update Behavior:

  • Complete Update - All fields must be provided in the request body
  • Field Validation - Each field is validated according to the rules above
  • Database Relations - Foreign key constraints are checked for route_id and seat_plan_id
  • Response Data - Returns updated fare with joined data from related tables

Notes:

  • The fare ID is required in the URL to specify which fare to update.
  • If the fare does not exist or has been deleted, the API will return a 404 error.
  • All required fields must be provided in the request body for a complete update.
  • The response includes updated data joined from related tables (routes, districts, seat_plans).
  • Amount should be specified in the smallest currency unit for precision.
  • Seat type determines the service class and pricing tier.