//找到app/Exceptions/Handler.php打开,添加下面代码,记得先use一下

1. use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
2. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

public function render($request, Exception $exception)
{

// 如果 不被允许的路由 或者不存在
if ($exception instanceof MethodNotAllowedHttpException || $exception instanceof NotFoundHttpException) {
if (!($request->ajax() || $request->wantsJson())) {
return response()->view('error.404');
}
}
return parent::render($request, $exception);
}

相关文章:

  • 2021-09-21
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2021-05-06
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2021-06-08
  • 2021-12-30
  • 2021-12-12
  • 2021-12-11
相关资源
相似解决方案