Laravel 404定制页面

时间:2019-10-12 10:04:27

标签: laravel laravel-5.8

我遇到了一个问题-我无法呈现Laravel 5.8 404错误的自定义视图。

我有一个resources/views/errors/404.blade.php文件,要显示给访问者。

根据Laravel文档(https://laravel.com/docs/5.8/errors#custom-http-error-pages)不再需要,应该显示404错误的自定义视图。

我有服务提供商,这是其boot方法:

public function boot ()
{

    abort (404); // if i generate a 404 error from here, everything works fine and 404.blade.php is displayed without problems

    View :: composer (['*'], function ($view) {

    abort (404); // but if i generate a 404 error from here, it displays NotFoundHttpException 

});

事实证明,从匿名函数调用abort (404)不允许您显示404错误的自定义视图

更新

如果我从匿名函数生成404错误,则会收到此异常:

Symfony\Component\Debug\Exception\FatalErrorException thrown with message "Uncaught Symfony\Component\HttpKernel\Exception\NotFoundHttpException in C:\Downloads\OSPanel\domains\site.com\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:992
Stack trace:
#0 C:\Downloads\OSPanel\domains\site.com\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(46): Illuminate\Foundation\Application->abort(404, '', Array)
#1 C:\Downloads\OSPanel\domains\site.com\app\Providers\SiteViewServiceProvider.php(70): abort(404)
#2 C:\Downloads\OSPanel\domains\site.com\app\Providers\SiteViewServiceProvider.php(42): App\Providers\SiteViewServiceProvider->getAntiLocaleURL()
#3 C:\Downloads\OSPanel\domains\site.com\vendor\laravel\framework\src\Illuminate\View\Concerns\ManagesEvents.php(164): App\Providers\SiteViewServiceProvider->App\Providers\{closure}(Object(Illuminate\View\View))
#4 C:\Downloads\OSPanel\domains\site.com\vendor\laravel\framework\src\Illuminate\Events\Dispatcher.php(344): Illuminate\View\Factory->Illuminate\View\Concerns\{closure}('composing: erro...', Array)
#5 C:\Do"

Stacktrace:
#0 Symfony\Component\Debug\Exception\FatalErrorException in C:\Downloads\OSPanel\domains\site.com\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:992

0 个答案:

没有答案