【问题标题】:Can't read new config variables in laravel 5.4无法在 laravel 5.4 中读取新的配置变量
【发布时间】:2017-04-19 10:27:23
【问题描述】:

我像这样在 laravel 中的config/app.php 文件中添加了一个新的配置变量

'foo' => 'pass'

但是当我尝试使用config('app.foo') 阅读它时,我不断收到null,而其他变量返回正确的值。我需要做什么?

【问题讨论】:

  • 请完整显示app.php
  • 你返回那个配置数组了吗?

标签: php laravel config laravel-5.4


【解决方案1】:

您使用的语法正确,请尝试使用以下命令清除配置缓存:

php artisan config:clear

【讨论】:

    【解决方案2】:

    无论何时更改配置,都必须清除旧缓存

    Laravel 将一些常用设置保存在缓存中,例如缓存文件夹中的配置、包和服务。如果您在 config/app.php 等中再次遇到 config 或 class not found 问题,那么您应该看到您的 缓存配置文件 (/laravel_project/bootstrap/cache/config.php)检查所需的东西是否可用。

    当您在虚拟主机上工作时,有时路由或视图不会呈现更改,那么您还需要清除该部分的缓存。

    为此,我们必须运行多个命令,例如:

     php artisan cache:clear
     php artisan view:clear
     php artisan route:clear
     php artisan config:clear
    

    但是每天写这些命令是一件很烦人的事情。所以我为它创建了一个包。 https://github.com/afrazahmmad/clear-all-cached-data。安装并运行:

    php artisan clear:data
    

    它会自动运行上述所有命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-04
      • 2015-11-10
      • 1970-01-01
      • 2015-03-01
      • 2019-01-29
      • 2022-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多