Laravel 5.2 {{ env('APP_ENV') }} 在生产中不起作用
Laravel 5.2 {{ env('APP_ENV') }} does not work in production
以下代码适用于我的开发环境(Ubuntu 14.04 桌面)
@if(env('APP_ENV') === 'production')
// ... something
但出于某种原因,blade 生产视图(ubuntu 14.04 服务器)没有获取环境变量。
如果我运行php artisan env
响应就好了:当前应用环境:production
数据库连接正常。从控制器调用的 env() 助手也可以工作。
到目前为止我尝试了什么:
php artisan clear:cache
php artisan config:cache
php artisan clear:cache
php artisan view:clear
我也重启过多次apache,都没有结果。
有什么建议吗?
谢谢!
所以,我成功了。
php artisan config:clear
成功了。
php artisan config:clear
php artisan cache:clear
service apache2 restart
(以防万一)
我猜问题是:
我第一次 运行 php artisan config:cache
我的 .env 文件有 APP_ENV=local。所以我必须清除配置缓存才能获得新的环境变量值。
而不是 env()
使用 \Config::get()
或 config()
。
https://laravel.com/docs/5.4/configuration#configuration-caching
What is difference between use env('APP_ENV'), config('app.env') or App::environment() to get app environment?
我解决了这个问题:
rm bootstrap/cache/config.php
以下代码适用于我的开发环境(Ubuntu 14.04 桌面)
@if(env('APP_ENV') === 'production')
// ... something
但出于某种原因,blade 生产视图(ubuntu 14.04 服务器)没有获取环境变量。
如果我运行php artisan env
响应就好了:当前应用环境:production
数据库连接正常。从控制器调用的 env() 助手也可以工作。
到目前为止我尝试了什么:
php artisan clear:cache
php artisan config:cache
php artisan clear:cache
php artisan view:clear
我也重启过多次apache,都没有结果。
有什么建议吗? 谢谢!
所以,我成功了。
php artisan config:clear
成功了。
php artisan config:clear
php artisan cache:clear
service apache2 restart
(以防万一)
我猜问题是:
我第一次 运行 php artisan config:cache
我的 .env 文件有 APP_ENV=local。所以我必须清除配置缓存才能获得新的环境变量值。
而不是 env()
使用 \Config::get()
或 config()
。
https://laravel.com/docs/5.4/configuration#configuration-caching
What is difference between use env('APP_ENV'), config('app.env') or App::environment() to get app environment?
我解决了这个问题:
rm bootstrap/cache/config.php