I am currently working on a laravel project. I need to redirect all error pages to 404 page not found page.
public function render($request, Exception $exception)
{
if ($this->isHttpException($exception)) {
switch ($exception->getStatusCode()) {
// not authorized
case '403':
return \Response::view('404',array(),403);
break;
// not found
case '404':
return \Response::view('404',array(),404);
break;
// internal error
case '500':
return \Response::view('404',array(),500);
break;
default:
return $this->renderHttpException($exception);
break;
}
} else {
return parent::render($request, $exception);
}
return parent::render($request, $exception);
}
Is there anyway to redirect error page to 404 page?. Also the validation errors are not displaying in this code(Redirecting to 404 when validation errors occurs). I am using the version 5.4.
Create Custom 404 Error Page You need to create blade views for error pages, move to this path resources/views/ inside here create errors folder and within the directory create 404. blade. php file. It will redirect you to the 404 page if you don't find the associated URL.
Through your config/app. php , set 'debug' => env('APP_DEBUG', false), to true . Or in a better way, check out your . env file and make sure to set the debug element to true.
Its Bug of Laravel 5.4 modified on laravel 5.5
https://github.com/laravel/framework/pull/18481
change file vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php
if (! $this->isHttpException($e) && config('app.debug')) {
return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
}
if (! $this->isHttpException($e)) {
return \Response::view('404',array(),500);
}
return $this->toIlluminateResponse($this->renderHttpException($e), $e);
How about:
if ($this->isHttpException($exception)) {
abort(404);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With