APP_DEBUG=true 被忽略

APP_DEBUG=true is being ignored

我在 .env 文件中有 APP_DEBUG=true

APP_ENV=local
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://test.dev

我故意使用不正确的 url(例如:test.dev/asdsadsa),它不在 web.php 路由文件中。

我希望在路由不存在时得到 laravel 调试错误

Sorry, the page you are looking for could not be found.
NotFoundHttpException in RouteCollection.php line 161:

但是,它一直显示 404 错误页面 (views/errors/404。blade.php) 即使 APP_DEBUG 设置为 true。

我尝试过的:

1 - 我什至进行了测试以确保 laravel 可以读取 .env 文件:

Route::get('/', function() { 
  dd(env('APP_DEBUG')); 
});

return true

2 - php artisan config:cache 没有修复它。

3 - chmod -R 777 storage 没有修复它。

删除确保你的 App\Exceptions\Handler$dontReport 这一行中没有:

'Symfony\Component\HttpKernel\Exception\HttpException'

查看文档:https://laravel.com/docs/5.3/errors#the-exception-handler

并找到:

Ignoring Exceptions By Type

The $dontReport property of the exception handler contains an array of exception types that will not be logged. For example, exceptions resulting from 404 errors, as well as several other types of errors, are not written to your log files. You may add other exception types to this array as needed

如果您在 views/errors 中有 404 错误页面,它将显示,如果没有,将显示 NotFoundHttpException

只需在错误视图中添加这两行,例如 views\errors4.blade.php

<?php $e = new Symfony\Component\Debug\ExceptionHandler(); ?>
<?php echo getenv('APP_DEBUG') == 'true' ? $e->getContent(Symfony\Component\Debug\Exception\FlattenException::create($exception)) : ''; ?>

这将在您的自定义 404 错误页面中显示 laravel 调试错误。

我来晚了,但如果没有别的办法,请尝试清除所有缓存,然后 运行:

php artisan optimize:clear

确保 laravel 项目的根文件夹中有 .env 文件。如果您没有,请搜索如何创建 laravel .env 文件并创建它。