How to Create Friendly Laravel Error Pages with Custom Debug Handling

This guide explains how to replace Laravel's default unfriendly error screens with a custom, user‑friendly page that adapts to the debug setting, displays helpful messages, and automatically redirects after a short delay.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
How to Create Friendly Laravel Error Pages with Custom Debug Handling

By default Laravel shows unfriendly error pages whether debug mode is on or off.

When debug is enabled the error page looks like the following:

When debug is disabled the error page looks like this:

You can customize the response by editing app/Exceptions/Handler.php and overriding the render method.

public function render($request, Exception $e)
{
    $debug = config('app.debug', false);
    if (empty($debug)) {
        // When debug is false, return a friendly page
        return response()->view('errors.503', ['info' => '好像走错了','url'=>'/']);
    }
    if ($e instanceof ModelNotFoundException) {
        $e = new NotFoundHttpException($e->getMessage(), $e);
    }
    return parent::render($request, $e);
}

The view errors/503.blade.php can contain a script that redirects after three seconds:

<script>
setTimeout(function(){
    window.location.href="{{$url or '/'}}";
},3000)
</script>

This ensures that any error will be displayed on a custom friendly page, showing a message and automatically redirecting after a short delay, which can be further styled for better user experience.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PHPError handlingLaravelCustom Error Page
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.