使用delete和put请求时报错

使用资源路由的delete请求时报错
路由:Route::resource(‘notice’, NoticeController::class);
用delete请求访问访问:xxx.xxx.xxx.xxx/notice/1
控制器代码:

public function destory(string $id)
{
    try {
        $this->notice->delete($id);

        return json_encode(['message'=>"公告删除成功",'data'=>[],'code'=>200]);
    } catch (Exception $e) {
        return json_encode(['message'=>$e->getMessage(),'data'=>[],'code'=>$e->getCode()]);
    }
}

报错:TypeError: Illuminate\Session\Middleware\StartSession::addCookieToResponse(): Argument #1 ($response) must be of type Symfony\Component\HttpFoundation\Response, null given, called in /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php on line 125 in file /www/wwwroot/test/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php on line 218

使用put请求时也会报一样的错,get和post可以正常使用,望各位大佬指点QAQ。

《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

你路由是不是有什么中间件验证

1年前 评论
Disenchant (楼主) 1年前
讨论数量: 6
return response()->json([...]);
1年前 评论

你路由是不是有什么中间件验证

1年前 评论
Disenchant (楼主) 1年前

Route::resource ('notice', NoticeController::class)->only(['destory']); 这样??

1年前 评论

StartSession 是一个有前置和后置操作的中间件,找它后边的中间件,没有返回正确的响应对象($response) ,大概率是逻辑判断没有提供返回值,默认返回值就是 null

1年前 评论

检查VerifyCsrfToken.php这个中间件后发现,默认是只支持POST和GET,增加了DELETE和PUT之后就可以正常使用了 ,感谢各位大佬指点

1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!