how to show 404 page in laravel code example
Example 1: 404 page in laravel
public function render($request, Throwable $exception)
{
if ($exception instanceof AccessDeniedHttpException) {
return response(view('errors.404'), 404);
}
return parent::render($request, $exception);
}
Example 2: show 500 or 404 page in laravel
public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException) {
return response()->view('errors.404', [], 404);
}
if ($this->isHttpException($e)) {
return $this->renderHttpException($e);
} else {
if (app()->environment() == 'production') {
return response()->view('errors.500', [], 500);
}
return parent::render($request, $e);
}
}
Example 3: how to set 404 page in laravel
public function render($request, Exception $exception)
{
if ($this->isHttpException($exception)) {
if ($exception->getStatusCode() == 404) {
return response()->view('errors.' . '404', [], 404);
}
}
return parent::render($request, $exception);
}