【问题标题】:Unable to load custom config in Laravel 5无法在 Laravel 5 中加载自定义配置
【发布时间】:2016-04-08 19:03:35
【问题描述】:

我有一个自定义配置

/home/me/www/mysite/config/searchService.php

返回

return array('myConsumerKey' => 'superSecretStuff',
'baseUrl' => 'superSecretStuff');

我在我的控制器中使用它

    $this->myConsumerKey = Config::get('searchService.myConsumerKey');
    $this->baseUrl = Config::get('searchService.baseUrl');

但是两者都返回 null

我试过了……

  • 作曲家转储-自动加载清除缓存
  • 清除缓存
  • 将文件添加到我的作曲家自动加载中
  • 文件的文件权限与其他工作配置相同
  • Apache 是文件的所有者

非常感谢任何其他帮助。

谢谢

【问题讨论】:

  • 只是为了检查一下,您已经尝试过:php artisan config:clear ?
  • 哦等等,这已经成功了!!对于任何看到这个的人,我会推荐 composer dump-autoload & config:clear,如果这仍然不起作用,请再次执行相同的两个操作,只是相反。干杯

标签: php laravel-5


【解决方案1】:

在 Laravel 5 中,您可以使用 config() 辅助函数。

config('searchService.myConsumerKey');

【讨论】:

  • 您好,感谢您的回复。恐怕即使使用该方法它仍然返回null,由于某种原因找不到它:/
  • 请用dd(\Config::get('searchService.php'))检查路径。
猜你喜欢
  • 2014-05-10
  • 2016-07-19
  • 2016-05-15
  • 2017-11-06
  • 2018-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-24
相关资源
最近更新 更多