Configure Whoops with Laravel 5.5 to open files with PHP Storm

Just like how it was, only different.

Categories: Development

Nothing new about Laravel 5.5 using Whoops, But one thing that I wanted to touch on was how to Configure Whoops in Laravel 5.5 to open files with PHP Storm, Or any other supported editor.
My previous example worked until I did a Composer update, I got an error.

My first idea was to dig out the old code with the now classic ($request,
Exception $exception)
method. To my surprise everything worked fine, That was until Docker/CI tripped an error.

[ErrorException]
  Declaration of App\Exceptions\Handler::renderExceptionWithWhoops($request,
  Exception $exception) should be compatible with Illuminate\Foundation\Excep
  tions\Handler::renderExceptionWithWhoops(Exception $e)

Humm…

My renderExceptionWithWhoops also handled JSON responses and since renderExceptionWithWhoops is implemented in Laravels Core and no longer accepted $request they have to be handled independently.

protected function handleWhoopsies($request, Exception $exception)
{
    if ($request->ajax()) {
        return $this->renderJsonExceptionWithWhoops();
    } else {
        return $this->renderExceptionWithWhoops($exception);
    }
}

Here is the full Gist.

In short because renderExceptionWithWhoops no longer accepts $request I created a handler called handleWhoopsies and let it do the split for me.

This checks if the request is ajax or not and then calls renderJsonExceptionWithWhoops or calls renderExceptionWithWhoops as normal.

Composer update and everything seems to work great.

Let me know if you had troubles configuring Whoops and if you found this helpful!


Adam Patterson

Adam Patterson

User Interface Designer & Developer with a background in UX. I have spent 5 years as a professionally certified bicycle mechanic and ride year-round.

I am a husband and father of two, I enjoy photography, music, movies, coffee, and good food.

You can find me on Twitter, Instagram, and YouTube!