Method 01
Instantiating Whoops in the render method doesn’t work quite like it did in 5.1. The render method in Laravel’s exception handler actually handles a number of default exceptions for you, like the validation HTTP exception or the ModelNotFoundException. In these instances you might actually want the page to render with the validation errors or the 404, so it’s better to let them be handled that way. Instead, you can override the method in app/Exceptions/Handler.php that generates the Symfony exception response and instead use Whoops.
/**
* 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);
}
Method 02
composer require filp/whoops
then in app/Exceptions/Handler.php
public function render($request, Exception $e)
{
// return parent::render($request, $e);
if (config(‘app.debug’) && ! $request->ajax()) {
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
return $whoops->handleException($e);
}
return parent::render($request, $e);
}