gpt4 book ai didi

laravel - 我想将 Laravel 5.2 版默认 404 页面重定向到我的 404 模板页面,从哪里和什么地方改变

转载 作者:行者123 更新时间:2023-12-03 07:56:54 25 4
gpt4 key购买 nike

我使用的是 Laravel 5.2 版,但不知道如何将 Laravel 默认页面重定向到我的模板 404 页面

最佳答案

使用 abort(404);

Some exceptions describe HTTP error codes from the server. For example, this may be a "page not found" error (404), an "unauthorized error" (401) or even a developer generated 500 error. In order to generate such a response from anywhere in your application, use the following:

abort(404);


如果您调用 abort(404);在你的路线或 Controller 的任何地方,它都会抛出 HTTPNotFoundException查找要在 resources/views/errors/ 中显示的 Blade 模板文件名与错误代码相同的目录。

例子:

在您的 app/Http/routes.php
Route::get('/test', function(){
return abort(404);
});

在您的 resources/views/errors/目录创建 404 .blade.php,注意文件名对应中止( 404 );

引用: https://laravel.com/docs/5.2/errors#http-exceptions

关于laravel - 我想将 Laravel 5.2 版默认 404 页面重定向到我的 404 模板页面,从哪里和什么地方改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35837214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com