如何禁用 laravel 5.4 默认错误处理程序

how to disable laravel 5.4 default error handler

我目前正在做一个 laravel 项目。我需要将所有错误页面重定向到 404 页面未找到页面。

public function render($request, Exception $exception)
        {
            if ($this->isHttpException($exception)) {
                switch ($exception->getStatusCode()) {

                        // not authorized
                        case '403':
                                return \Response::view('404',array(),403);
                                break;

                        // not found
                        case '404':
                                return \Response::view('404',array(),404);
                                break;

                        // internal error
                        case '500':
                                return \Response::view('404',array(),500);
                                break;

                        default:
                                return $this->renderHttpException($exception);
                                break;
                }
        } else {
                return parent::render($request, $exception);
        }



                return parent::render($request, $exception);
        }

有没有办法将错误页面重定向到 404 页面?。此外,此代码中未显示验证错误(发生验证错误时重定向到 404)。我使用的是 5.4 版本。

resources/views/errors

中创建一个目录

在此目录中创建文件

404.blade.php 404 错误。

500.blade.php 400 错误。

403.blade.php 403 错误。

这些视图将自动呈现。 要中止应用程序,您可以使用 abort(404)

希望对您有所帮助。

检查下面的代码是否在"handler.php"

"use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;"

并检查错误资源文件。
( https://laracasts.com/discuss/channels/general-discussion/how-do-i-create-a-custom-404-error-page )

并且您可以在处理程序中使用中止函数

怎么样:

if ($this->isHttpException($exception)) {
    abort(404);
}

Laravel 5.4 的 Bug 在 laravel 5.5

上修改

https://github.com/laravel/framework/pull/18481

更改文件 vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php

if (! $this->isHttpException($e) && config('app.debug')) {
        return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
    }
    if (! $this->isHttpException($e)) {
       return \Response::view('404',array(),500);
    }
    return $this->toIlluminateResponse($this->renderHttpException($e), $e);