1

I'm trying to update data in the database but it returns error 404 not found in postman

Route::put('/products/{id}','productController@update');
Karl Hill
  • 12,937
  • 5
  • 58
  • 95
hala
  • 161
  • 2
  • 13

2 Answers2

0

Just add 'Accept: application/json' header to request.

Świeżu
  • 176
  • 2
  • 6
-1

Please provide more code so we can find exactly where your problem is.

I assume you wrote the route in the api.php file and not in web.php file.

If you do so, you must enter the route as api/products/1.

You have to be aware of the route group prefix as well if you are using it. Every routes inside a group prefix will be wrapped and requires the prefix string in the beginning every time you want to access it.

For instance:

in web.php file:

Route::group(['prefix' => 'api'], function () {
    Route::put('products/{id}', 'productController@update');
});

# this will require you to access the url by tyiping "api/products/1".

and in the api php file (this is the more likely for new users have to be aware):

Route::group(['prefix' => 'api'], function () {
    Route::put('products/{id}', 'productController@update');
});

# this will require you to access the url by tyiping "api/api/products/1" since the api.php file will automatically wrap your routes within an api prefix.

and one more thing you need to know, if you are using a getRoutesKeyName method on your model, you should follow wether the wildcard to use id's or maybe slug based on what you type inside the method.

For instance:

public function getRoutesKeyName(){
    return 'slug';
}
# this will require you to type "products/name-of-product" instead of "products/1"
Yura
  • 1,937
  • 2
  • 19
  • 47
  • no need to add `['prefix' => 'api']`, if the route is listed api.php, `/api` is automatically added to these routes, – Aditya Thakur May 09 '19 at 05:22
  • @AdityaThakur that is just an example to get 404 error on your api routes. I don't say that you need to add prefix, just be aware of using it. please read carefully. – Yura May 09 '19 at 10:56