How to disable laravel 5.4 default error handler

I am currently working on a laravel project. I need to redirect all error pages to a page with 404 pages not found.

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); } 

Can I redirect the error page to page 404 ?. Also, verification errors are not displayed in this code (redirecting to 404 when verification errors occur). I am using version 5.4.

+5
source share
4 answers

His Laravel 5.4 bug changed to laravel 5.5

https://github.com/laravel/framework/pull/18481

change file provider /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); 
+5
source

What about:

 if ($this->isHttpException($exception)) { abort(404); } 
+2
source

Create a directory in resources/views/errors

Create files in this directory

404.blade.php for 404 error.

500.blade.php for error 400.

403.blade.php for error 403.

These views will be automatically displayed. to interrupt the application you can use abort(404)

Hope this helps.

+1
source

check if the code below is in "handler.php"

"use Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException;"

and check the error resource file.
( https://laracasts.com/discuss/channels/general-discussion/how-do-i-create-a-custom-404-error-page )

and you can use the interrupt function in your handler

+1
source

Source: https://habr.com/ru/post/1275723/


All Articles