Home > Backend Development > PHP Tutorial > laravel 5.1 当 APP_DEBUG 为 false 时,自定义错误页面

laravel 5.1 当 APP_DEBUG 为 false 时,自定义错误页面

WBOY
Release: 2016-06-20 12:49:06
Original
1677 people have browsed it

我们都知道,当 APP_DEBUG = false 时,我们展示的错误页面是这样的

那我们怎么来自定义这个页面呢?其实很简单,打开 app/Exceptions/Handler.php 我们来重写下这个文件

<?phpnamespace App\Exceptions;use Exception;use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;use Symfony\Component\Debug\ExceptionHandler as SymfonyDisplayer;class Handler extends  ExceptionHandler{    /**     *     * @param \Exception $e     *     * @return \Symfony\Component\HttpFoundation\Response     */    protected function convertExceptionToResponse(Exception $e)    {        $debug = config('app.debug', false);            if ($debug) {            // 当 debug 为 true 时,返回默认的报错页面            return (new SymfonyDisplayer($debug))->createResponse($e);        }            return response()->view('errors.default', ['expection' => $e], 500);    }}
Copy after login

然后就可以在 views/errors 下新建你的 default.blade.php 文件,自定义你页面吧

欢迎大家一起加群学习:365969825

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template