I have API URL like:
http://example.com/api/driverAcceptOrder?id=bee74e39-ff38-46a6-9e5d-6db799d2be8c&driverId=3453a3a9-7f58-434a-8dab-95c3469e6238
method is POST
and it takes 2 parameter id
and driverId
When I try to run this URL in postman I get:
Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException
Route
Route::post('driverAcceptOrder/{id}/{driverId}', 'Api\DriversController@driverAcceptOrder');
Controller
public function driverAcceptOrder(Request $request, $id, $driverId)
{
$order = Order::findOrFail($id);
$defs = OrderDefaultProgress::where('name', 'Driver OTW ke pelanggan')->first();
$driver = Driver::where('id', $driverId)->with('user')->first();
$order->update(['driver_id' => $driverId]);
return response()->json([
'data' => $driver,
'message' => 'Pengemudi Dalam perjalanan menuju pelanggan.'
], 200);
}
Note
- Route is not restricted by Auth middleware (its public)
- I've added exception to my
VerifyCsrfToken
file asprotected $except = ['/api/*'];
Any idea?
My Answer:
If you are getting a NotFoundHttpException in Laravel when trying to access the API URL `http://example.com/api/driverAcceptOrder?id=bee74e39-ff38-46a6-9e5d-6db799d2be8c`, it means that Laravel is not able to find a route that matches this URL.
To fix this issue, you need to define a route in your Laravel application that matches the API URL. You can do this by adding a route definition in your `routes/api.php` file or in your `routes/web.php` file if you are using web routes for your API.
Here is an example of how you can define a route that matches the API URL in your `routes/api.php` file:
php
Route::get('/driverAcceptOrder', function (Request $request) {
$id = $request->input('id');
// Your logic here
});
Make sure to replace `// Your logic here` with the actual logic you want to execute when this API endpoint is accessed.
After defining the route, you should be able to access the API URL `http://example.com/api/driverAcceptOrder?id=bee74e39-ff38-46a6-9e5d-6db799d2be8c` without getting a NotFoundHttpException.
Rate this post
4 of 5 based on 6734 votesComments