我正在尝试实现DELETE和PUT请求,但出现错误。下面是我的代码
$app->group('/departments', function () {
$this->put('/{id}', DepartmentController::class . ':update')->setName('department.update');
$this->delete('/{id}', DepartmentController::class . ':destroy')->setName('department.destroy');
});
[当我尝试运行代码时,出现此错误消息
Method not allowed. Must be one of: PUT, DELETE
我在这里想念什么吗?谢谢
我设法通过添加如下所示的隐藏输入法来解决问题。
//Update
<form action="{{path_for('department.update', {'id':department.id})}}" method="post">
<input type="hidden" name="_METHOD" value="PUT">
</form>
//Delete
<form action="{{path_for('department.destroy', {'id':department.id})}}" method="post">
<input type="hidden" name="_METHOD" value="DELETE">
</form>
和我的routest
$app->group('/departments', function () {
$app->put('/{id}', DepartmentController::class . ':update')->setName('department.update');
$app->delete('/{id}', DepartmentController::class . ':destroy')->setName('department.destroy');
});
尝试,
$app->group('/departments', function () {
$app->put('/{id}', DepartmentController::class . ':update')->setName('department.update');
$app->delete('/{id}', DepartmentController::class . ':destroy')->setName('department.destroy');
});