I have a REST api built with Laravel. in the routes I added:
DELETE /v1/category/{category} App\Http\Controllers\CategoriesController@destroy
On my local machine which has xampp
every thing works fine and the destroy
method is triggered. but on the production server when I request that route it treats it as GET
request and return the record of that category instead of deleting it.
To go around the issue I avoided using DELETE
requests so I registered the route as:
GET /v1/category/delete/{category} App\Http\Controllers\CategoriesController@destroy
Any Ideas why the DELETE
request treated as GET
?
Update: Here is the routes.php file:
<?php
/**
* Api Route Group V1
*/
RestRoute::group(['version' => 'v1', 'namespace' => 'App\Http\Controllers'], function () {
RestRoute::group(['prefix' => 'v1'], function () {
RestRoute::resource('articles', 'ArticlesController');
RestRoute::get('posts/user/{id}', 'PostsController@userPosts');
RestRoute::resource('posts', 'PostsController');
RestRoute::resource('items', 'ItemsController');
RestRoute::get('recipes/all', 'RecipesController@showAll');
RestRoute::resource('recipes', 'RecipesController');
RestRoute::resource('profile', 'ProfileController');
RestRoute::get('tag', 'TagsController@index');
RestRoute::get('tag/{tag}', 'TagsController@show');
RestRoute::get('tag/{tag}/articles', 'TagsController@tagArticles');
RestRoute::post('category', 'CategoriesController@store');
RestRoute::get('category/list', 'CategoriesController@CategoriesList');
RestRoute::get('category/recipes/{category}', 'CategoriesController@showRecipes');
RestRoute::get('category/{category}', 'CategoriesController@show');
RestRoute::patch('category/{category}', 'CategoriesController@update');
RestRoute::delete('category/{category}', 'CategoriesController@destroy');
RestRoute::post('authenticate', 'AuthenticateController@authenticate');
RestRoute::get('authenticate/logout', 'AuthenticateController@logout');
RestRoute::post('register', 'AuthenticateController@store');
});
});