Laravel 5.7 错误 404 处理页面位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52261128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:02:32  来源:igfitidea点击:

Laravel 5.7 error 404 handling page location

phplaravelerror-handling

提问by MoncefB

I couldn't find the location of the error 404 page in Laravel 5.7 please help. here is the error page photo : https://imgur.com/a/Fs89isK

我在 Laravel 5.7 中找不到错误 404 页面的位置,请帮忙。这是错误页面照片:https: //imgur.com/a/Fs89isK

采纳答案by ilubis

actually you can override it in app/Exceptions/Handler.php

实际上你可以覆盖它 app/Exceptions/Handler.php

and set the code look like this.

并将代码设置为这样。

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;


class Handler extends ExceptionHandler
{
if ($this->isHttpException($exception)) {
        if ($exception instanceof NotFoundHttpException) {
            return response()->view('error_404_path', [], 404);
            // abort(404);
        }
        return $this->renderHttpException($exception);
    }
}

回答by latr.88

You can find it here:

你可以在这里找到它:

vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/views/404.blade.php

You shouldn't be editing this file directly though. If you want to add your custom error page just add an errors folder inside the resources/views and create your own 404.blade.php as desired. It will be used instead of Laravel's one.

不过,您不应该直接编辑此文件。如果您想添加自定义错误页面,只需在资源/视图中添加一个错误文件夹并根据需要创建您自己的 404.blade.php。它将被用来代替 Laravel 的。

回答by GabMic

With every change to the framework by updating, you will override any core function. Add an errorsfolder in your viewsdirectory, and place blade files with the error number you wish to modify.

通过更新对框架的每次更改,您将覆盖任何核心功能。errors在您的views目录中添加一个文件夹,并放置带有您要修改的错误号的刀片文件。

For example:

例如:

resources->views->errors->404.blade.php

resources->views->errors->404.blade.php

will be shown on 404 responses. And by the way, if you love(like me) the news errors svg, you can find the in public->svgfolder.

将显示在 404 响应中。顺便说一句,如果你喜欢(像我一样)新闻错误 svg,你可以找到 inpublic->svg文件夹。

回答by Stevie B

If you run php artisan vendor:publish you can see a list of vendor / package files that can be published for editing.

如果您运行 php artisan vendor:publish 您可以看到可以发布以进行编辑的供应商/包文件列表。

In the list you will see laravel-errors

在列表中你会看到 laravel-errors

Type the corresponding number then you will see.

输入相应的数字,然后你就会看到。

Copied Directory [/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/views] To [/resources/views/errors] Publishing complete.

复制目录 [/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/views] 至 [/resources/views/errors] 发布完成。

You can then edit all the default error pages, including 404.blade.php 500.blade.php etc.

然后您可以编辑所有默认错误页面,包括 404.blade.php 500.blade.php 等。