Install Whoops (prefer version 2)
cd projectfolder
composer require filp/whoops
Or edite composer.json and set require values, like this:
...
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"filp/whoops": "2.1.*"
},
...
After run:
cd projectfolder
composer update
Open projectfolder/app/Exceptions/Handler.php
and replace function render
by example in gist:
public function render($request, Exception $e)
{
if ($e instanceof HttpException) {
return parent::render($request, $e);
}
$whoops = new \Whoops\Run;
if ($request->ajax()) {
$whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
} else {
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
}
return new \Illuminate\Http\Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
}
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Validation\ValidationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
* @return void
*/
public function report(Exception $e)
{
parent::report($e);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof HttpException) {
//HTTP errors don't need Whoops
return parent::render($request, $e);
}
$whoops = new \Whoops\Run;
if ($request->ajax()) {
$whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler());
} else {
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler());
}
return new \Illuminate\Http\Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
}
}