Created
February 24, 2017 10:33
-
-
Save shawnsandy/08e7af37075620439d4c24c522146652 to your computer and use it in GitHub Desktop.
Laravel Custom 404
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(env("APP_DEBUG") === FALSE): | |
// 404 page when a model is not found | |
if ($exception instanceof ModelNotFoundException or $exception instanceof NotFoundHttpException) { | |
return response()->view('extras::errors.404', $request, 404); | |
} | |
if ($this->isHttpException($exception)) { | |
//return $this->renderHttpException($exception); | |
// mirrored code from renderHttpException to allow for exception-less errors in non-dev mode | |
$status = $exception->getStatusCode(); | |
if (view()->exists("errors.{$status}")) { | |
return response()->view("extras::errors.{$status}", $request, $status, $exception->getHeaders()); | |
} else { | |
return $this->convertExceptionToResponse($exception); | |
} | |
} else { | |
// Custom error 500 view on production | |
return response()->view('extras::errors.500', $request, 500); | |
} | |
endif; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment