使用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 框架的设计哲学。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
最佳答案

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

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年前 评论

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