Errors are handled within the App\Exceptions\Handler . To render a 404 page, change the render() method to this:
public function render($request, Exception $e) { if($e instanceof NotFoundHttpException){ return response(view('errors.404'), 404); } return parent::render($request, $e); }
And add this to the top of the Handler.php file:
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Edit: As @YiJiang points out, the response should not only return a 404 view, but also contain the correct status code. Therefore, view() must be enclosed in a response() call passing at 404 as a status code. Like in the edited code above.
source share