Laravel Framework

David Carr

Laravel 5.3 install whoops

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:

Support my work by donating with PayPal.

Subscribe to my newsletter

Subscribe and get my books and product announcements.

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