Laravel 5.3 install whoops

David Carr

Laravel 5.3 install whoops

Laravel Framework

In older versions of Laravel error’s where displayed using the Whoops. In recent versions it’s not used. If like me you would like to you use Whoops this post is for you!

To bring back Whoops add it to composer:

"filp/whoops": "~2.0"

Then do a ‘composer update’

Next open App\Exceptions\Handler.php and add this method: thanks to jacurtis

/**
 * Create a Symfony response for the given exception.
 *
 * @param  \Exception  $e
 * @return mixed
 */
protected function convertExceptionToResponse(Exception $e)
{
    if (config('app.debug')) {
        $whoops = new \Whoops\Run;
        $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);

        return response()->make(
            $whoops->handleException($e),
            method_exists($e, 'getStatusCode') ? $e->getStatusCode() : 500,
            method_exists($e, 'getHeaders') ? $e->getHeaders() : []
        );
    }

    return parent::convertExceptionToResponse($e);
}

That’s it now error pages will look this:

Laravel Modules Book by David Carr

Help support the blog so that I can continue creating new content!

Subscribe to my newsletter

Subscribe and get my books and product announcements.

© 2009 - 2022 DC Blog. All code MIT license. All rights reserved.