laviku
laviku

Reputation: 541

How to set a different 404 error page on Laravel?


I want to make a custom 404 error page to show on production with Laravel. But I don't know wich file do I have to edit or if I have to create a new one and where do I have to create it? All I have found is related to handling errors but that's not what I want.
What I mean is that I want to show something like this: 404 error page

Thanks in advanced!

Upvotes: 0

Views: 945

Answers (1)

davidxd33
davidxd33

Reputation: 1206

You can override Laravel's handling of errors in app/start/global.php

Look for App::error and replace it with :

App::error(function(Exception $exception, $code)
{
    Log::error($exception);

    if ( ! in_array($code,array(401,403,404,500))){
       return;
    }

    $data = array('code'=> $code);

    switch ($code) {

       case 403:

         return Response::view('errors.error', $data, $code);

       break;

       case 404:

         return Response::view('errors.error', $data, $code);

       break;

   }


});

You can then specify custom views for errors based on the error code.

Upvotes: 3

Related Questions