i got this error:Client error: GET https://api.openrouteservice.org/v2/directions/driving-car?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&start=12%20Ukehe%20Street%2C%20independence%20layout%2C%20Enugu%2CNigeria&end=19%20Ebony%20Paint%20Road%2C%20Garriki%2C%20Enugu%2C%20Nigeria
resulted in a 400 Bad Request
response: {“error”:{“code”:2003,“message”:"Parameter ‘12 Ukehe Street, independence layout, Enugu,Nigeria’ has incorrect value or (truncated…)
What did I do wrong please.
Here’s my controller file:
<?php namespace App\Http\Controllers; use App\Booking; use Illuminate\Support\Facades\Auth; use Illuminate\Http\Request; use App\Models\User; use App\Models\TranWallet; use GuzzleHttp\Client; class CabController extends Controller { public function showBookCabForm() { // Fetch user's wallet balance and pass it to the view $user = auth()->user(); $wallet = TranWallet::where('user_id', $user->id)->first(); $walletBalance = $wallet ? $wallet->balance : 0; return view('backend.cab_booking.user_cab_booking', compact('walletBalance')); } public function bookCab(Request $request) { // Validate the request data $request->validate([ 'pickup_location' => 'required', 'destination' => 'required', 'vehicle_type' => 'required|in:standard,premium,keke', // Add validation for vehicle type ]); // Replace 'YOUR_OPENROUTESERVICE_API_KEY' with your actual API key $apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // Calculate distance using OpenRouteService API $distance = $this->calculateDistance($request->input('pickup_location'), $request->input('destination'), $apiKey); // Perform fee calculation based on distance and vehicle type $fee = $this->calculateFee($distance, $request->input('vehicle_type')); // Check user's wallet balance $user = Auth::user(); if ($user->wallet_balance >= $fee) { // Create a new booking $booking = new Booking([ 'user_id' => $user->id, 'pickup_location' => $request->input('pickup_location'), 'destination' => $request->input('destination'), 'distance' => $distance, 'fee' => $fee, 'vehicle_type' => $request->input('vehicle_type'), ]); $booking->save(); // Deduct the fee from the user's wallet $user->wallet_balance -= $fee; $user->save(); // Save wallet transaction details $walletTransaction = new WalletTransaction([ 'user_id' => $user->id, 'amount' => -$fee, 'type' => 'debit', 'description' => 'Cab Booking', ]); $walletTransaction->save(); return view('backend.cab_booking.user_cab_booking')->with('success', 'Booking successful!'); } else { // Insufficient funds, redirect to top-up page $balance = $user->wallet_balance; // Pass wallet balance to the top-up view return view('backend.topupwallet.topupwallet', compact('balance'))->with('error', 'Insufficient funds. Please top up your wallet.'); } } // Helper method to calculate distance using OpenRouteService API private function calculateDistance($pickupLocation, $destination, $apiKey) { $client = new Client(); $response = $client->get('https://api.openrouteservice.org/v2/directions/driving-car', [ 'query' => [ 'api_key' => $apiKey, 'start' => $pickupLocation, 'end' => $destination, ], ]); $data = json_decode($response->getBody(), true); // Assuming 'distance' is in the first element of the 'features' array return $data['features'][0]['properties']['segments'][0]['distance'] ?? 0; } // Helper method to calculate fee based on distance and vehicle type private function calculateFee($distance, $vehicleType) { // Your fee calculation logic based on distance and vehicle type // This is a placeholder, you should replace it with your actual logic $baseFee = 5; // Base fee for any ride $additionalFeePerKm = 1.5; // Additional fee per kilometer if ($vehicleType === 'premium') { // Adjust fee for premium vehicles $additionalFeePerKm = 2.5; } elseif ($vehicleType === 'keke') { // Adjust fee for keke $additionalFeePerKm = 0.8; } $fee = $baseFee + ($distance / 1000) * $additionalFeePerKm; return $fee; } } I need help please