I'm trying to update data in the database but it returns error 404 not found in postman
Route::put('/products/{id}','productController@update');
I'm trying to update data in the database but it returns error 404 not found in postman
Route::put('/products/{id}','productController@update');
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"