Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alecxi's avatar

How to register a custom 404 in Laravel 5

Upgraded to Laravel 5 just recently to build a couple of websites for clients, and everything I know about registering a custom 404 page has completely flat lined. Has anybody figured this out yet?

0 likes
7 replies
bestmomo's avatar
Level 52

Just add it in app/Http/Kernel.php :

public function handle($request)
{
    try
    {
        return parent::handle($request);
    }
    catch(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e)
    {
        return response()->view('my.missing', [], 404);
    }
    catch (Exception $e)
    {
        $this->reportException($e);

        return $this->renderException($request, $e);
    }
}

You can also add the report of the exception if you want to get it in log.

3 likes
bestmomo's avatar

This info is now obsolete because you just have to create a resources/views/errors/404.blade.php.

2 likes
jackbarham's avatar

Do you mean my reply? That's interesting, so just add in a 404.blade.php in views/errors and it will handle it automatically you mean?

1 like
bobbybouwmann's avatar

Yea Laravel will handle it for you ;) And out of my head you will have access to $code, $message, $headers

1 like
kaju74's avatar

Hmm...Not sure how to display the optional message inside a custom error-blade-template...

{{ $message }}

will result into a 'undefined variable' error.

Please or to participate in this conversation.