0

I have a database with two tables: table CATEGORIES has an id that is the fk of table PRODUCTS. When I want to delete a category, and a record in table products has associated that category id, laravel return a 405 error and i cannot access to destroy method. How can I avoid 405 error and access to destroy method?

Here's my route config:

$api = app('Dingo\Api\Routing\Router');

$api->version('v1',['middleware' => ['api']], function($api){

   $api->resource('categories', 'App\Http\Controllers\CategoriesController');
   $api->resource('products', 'App\Http\Controllers\ProductsController');
   $api->get('categories/{id}/products', 'App\Http\Controllers\CategoriesController@products');

});

EDIT

If the category isn't associated with any product, delete method doesn't throw any error so I guess it isn't a route problem

Matteo Meil
  • 1,192
  • 10
  • 20

1 Answers1

1

Laravel only returns HTTP 405 if a route exists but not for that method. I'm not entirely familiar with Dingo, but run php artisan route:list to check that the route you're trying to use has been registered for a DELETE request.

Dwight
  • 12,120
  • 6
  • 51
  • 64
  • For dingo api I've already used its command to display all routes and the method is in the list, so I guess it isn't a registration problem – Matteo Meil Apr 08 '17 at 14:51
  • Are you not meeting the route requirements when calling it, perhaps missing the `v1` versioning (however you have that implemented) or failing the `api` middleware? – Dwight Apr 10 '17 at 00:36
  • I don't think I'm missing some route requirements because, as I wrote in edit section, the method I call do its behaviour as expected if the category I want to delete isn't associated without any product. However I noticed that i get problems when I pass an array insted of a single id: if i pass a single id the method work as expected but if I send an entire array of ids to delete I get 405 error. This sounds strange for me. (Sorry for my english, I'm not english so I write as I can) – Matteo Meil Apr 12 '17 at 19:16