Laravel(5.4)在有效的API路由上抛出404

时间:2018-11-22 10:26:39

标签: laravel http-status-code-404

我一直在尝试使用各种不同的建议来解决此问题,但似乎没有任何效果,尽管我可能遗漏了一些明显的东西,但我只是不明白为什么我在路线上遇到404错误肯定存在。

我有一个CRM,它除了其他选项外,还允许用户删除“可交付结果”(附在案子上的文件),但是由于某种原因,我总是在尝试执行时得到404。

这是React组件中的调用:

documentCollectionRepo.removeDeliverable(deliverable.id).then(showSuccess, showError);

deliverable.id确实存在,因为我已将控制台注销。

这是仓库中的函数:

export function removeDeliverable(documentCollectionId) {
   return Api.remove(`document-collections/${documentCollectionId}`);
}

最后,这是API路由文件中的路由:

Route::delete('document-collections/{documentCollectionId}', 'DocumentCollectionController@deleteDocumentCollection');

当我单击“删除”按钮以运行相关功能时,“网络”选项卡显示以下错误(此引号中隐藏了IP):

  

请求网址:http://192.168.50.52/api/v1/document-collections/3
  请求方法:DELETE
状态码:404未找到
远程地址:   192.168.xx.xx:80
推荐人政策:降级时不推荐人

deleteDocumentCollection()函数确实存在于DocumentCollectionController.php文件中,并且所有其他函数都可以工作(包括另一个删除路由)-因此我不太明白为什么该路由不起作用。任何对此的帮助将不胜感激。

编辑:

这是控制器功能:

public function deleteDocumentCollection(DeleteDocumentCollectionRequest $req, $documentCollectionId)
{
    $this->documentCollectionRepository->delete($documentCollectionId);

    return response()->ok();
}

在回购中:

public function delete($fileId)
{
    $file = $this->getOne($fileId);

    $this->deleteUploadedFile($file);
    $this->deleteNotifications($file);
    $this->deleteNotes($file);

    $file->delete();
}

1 个答案:

答案 0 :(得分:0)

如果您在Apache上配置了Laravel Project,则可能会发生此类问题。

由于Apache不允许DELETE请求,因此响应为404。

在Laravel默认代码之后将其添加到.htaccess:

<Limit DELETE>
  Order deny,allow
  Allow from all
</Limit>

再次可能是这种情况。如果仍然无法使用,请简要分享您的代码,以便我进行调查。

谢谢。