Reputation: 5664
In my routes.php
, when I have:
Route::delete('page/{id}', function ($id)
{
return "deleting $id";
});
And I send a delete
or get
request using Postman, This throws a MethodNotAllowedHttpException
.
When I change routes.php
:
Route::get('page/{id}', function ($id)
{
return "deleting $id";
});
It responds the string deleting...
in response to GET
, DELETE
and PUT
!
But the HTTP code is 403.
It just throws a MethodNotAllowedHttpException
on a POST
request.
This problem seems to occur only on remote server and it works as expected on localhost.
Is there anything in Laravel that maybe redirects or changes methods to GET
?
Upvotes: 1
Views: 5466
Reputation: 5664
It's because Apache doesn't allow DELETE
requests, and that's why the response code is a "403 forbidden".
Add this to .htaccess
after the Laravel default codes:
<Limit DELETE>
Order deny,allow
Allow from all
</Limit>
see this answer: https://stackoverflow.com/a/1402480/2543240
Upvotes: 1
Reputation: 165
Try to add this to your form, above delete button:
{!! method_field('DELETE') !!}
<input type="hidden" name="_method" value="DELETE">
Upvotes: 0