【发布时间】:2025-11-29 13:45:01
【问题描述】:
我是 laravel 的新手,如果用户使用错误的 HTTP 方法点击 url,我想处理异常。我想以 json 格式发送用户响应,但代码不起作用,有时它会给出空白页。以下是我的代码:
处理程序.php
public function render($request, Exception $exception)
{
if ($exception instanceof MethodNotAllowedHttpException) {
return response()->json(['error' => 'Bad Request.'], 404);
}
}
提前致谢
【问题讨论】:
标签: php exception-handling laravel-5.3