Skip to content

Instantly share code, notes, and snippets.

@shawnsandy
Created February 24, 2017 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawnsandy/08e7af37075620439d4c24c522146652 to your computer and use it in GitHub Desktop.
Save shawnsandy/08e7af37075620439d4c24c522146652 to your computer and use it in GitHub Desktop.
Laravel Custom 404
<?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