Laravel路由方法DELETE不起作用 [英] Laravel route method DELETE not working
问题描述
在我的 routes.php
中,当我有以下内容时:
In my routes.php
, when I have:
Route::delete('page/{id}', function ($id)
{
return "deleting $id";
});
然后我使用邮递员发送 delete
或 get
请求,这将引发 MethodNotAllowedHttpException
.
And I send a delete
or get
request using Postman, This throws a MethodNotAllowedHttpException
.
当我更改 routes.php
时:
Route::get('page/{id}', function ($id)
{
return "deleting $id";
});
它响应 GET
, DELETE
和 PUT
来响应字符串 deleting ...
!但是HTTP代码是403.
It responds the string deleting...
in response to GET
, DELETE
and PUT
!
But the HTTP code is 403.
它只是在 POST
请求上抛出 MethodNotAllowedHttpException
.
此问题似乎仅在远程服务器上发生,并且可以在localhost上按预期方式工作.
This problem seems to occur only on remote server and it works as expected on localhost.
Laravel中是否有任何可能将方法重定向或更改为 GET
的方法?
Is there anything in Laravel that maybe redirects or changes methods to GET
?
推荐答案
这是因为Apache不允许 DELETE
请求,这就是为什么响应代码是"403禁止"的原因.
It's because Apache doesn't allow DELETE
requests, and that's why the response code is a "403 forbidden".
在Laravel默认代码之后将其添加到 .htaccess
:
Add this to .htaccess
after the Laravel default codes:
<Limit DELETE>
Order deny,allow
Allow from all
</Limit>
查看此答案: https://stackoverflow.com/a/1402480/2543240
这篇关于Laravel路由方法DELETE不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!