Laravel 5.3 install whoops

David Carr

1 min read - 15th Dec, 2016

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:

0 comments
Add a comment

Copyright © 2024 DC Blog - All rights reserved.