Search code examples
phplaravellaravel-8ignition

Remove stack trace from Laravel error page


How would i remove the lengthy stack trace errors that Laravel uses by default? (i understand it is using "Ignition")

Some resources that i've found that did not help:

  • this thread only mentions how to disable error reporting altogether
  • when i write anything in a render() method in the app/Exceptions/Handler.php like mentioned here i only get error 500 without any output.
  • person in this thread even suggests writing your own Laravel bootstrap application instead of using the default one, breaking Laravel framework semantics, but that's just plain mad.

I have also tried looking at configuration values for Ignition by publishing ignition config file via

php artisan vendor:publish --provider="Facade\Ignition\IgnitionServiceProvider" --tag="ignition-config"

But that file has nothing to configure, the only thing you can do is to hide the "share" message in the error.

I just want a simple classic php error page with file/line/error, no stack traces, or no html markup. The error page makes it really difficult to debug output in anything else than a web browser.


Solution

  • Simply override the render() method in your app's exception handler. Per comments in the base class, this method must return a response object.

    public function render($request, \Throwable $e)
    {
        return response()->view("exception", ["exception" => $e]);
    }
    

    Then make your blade view look however you want.

    <!doctype html>
    <title>Exception</title>
    <body>
    <p>
    Exception of type <code>{{ get_class($exception) }}</code>
    thrown in <code>{{ $exception->getFile() }}</code>
    on line <code>{{ $exception->getLine() }}</code>.
    </p>
    </body>