Reputation: 881
I've a route defined as below:
Route::resource('api/invoice', 'InvoiceController');
In my controller I have a function destroy($id)
When sending a DELETE
request to /api/invoice
with an id: 2
as parameter and I get a 405 error message back.
I tried accessing this route from Postman and from a javascript code directly, without success...
Any ideas?
Upvotes: 2
Views: 4482
Reputation: 881
405 error was returned because the request URL wasn't matching the DELETE URI:
Expected destroy URI: DELETE api/invoice/{invoice} Used destroy URI: DELETE api/invoice?id=1
As simple as that...
Upvotes: 0
Reputation: 146269
You said I get a 405 error
and that is because of wrong HTTP Method
, in your Resource Controller
you have the destroy
method and in this case this method is accessible using a DELETE
request. So make sure you are sending a DELETE
request for this.
You may run the following command from your terminal/command prompt:
php artisan routes
It'll output the routes with their names and URL
so find the route and check the request method and URL
to access that method. Check HTTP Error 405 Method not allowed for more information. If you are using JavaScript/AJAX
to invoke the destroy
method then, check this answer.
Upvotes: 2