Laravel 5.2 {{ env('APP_ENV') }} does not work in production

倾然丶 夕夏残阳落幕 提交于 2019-12-10 14:32:14

问题


The following code works on my development environment (Ubuntu 14.04 desktop)

@if(env('APP_ENV') === 'production')
    // ... something

But for some reason, the blade views on production (ubuntu 14.04 server) aren't getting the env variables.

If I run php artisan env the response is just fine: Current application environment: production

The database connection works fine. And the env() helper called from the controllers, also works.

What I tried so far:

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

I also restarted apache multiple times, no results.

Any advice? Thanks!


回答1:


So, I made it work.

php artisan config:clear did the trick.

  1. php artisan config:clear
  2. php artisan cache:clear
  3. service apache2 restart (just in case)

What I guess the problem was:

The first time I run php artisan config:cache my .env file had APP_ENV=local. So I had to clear that config cache in order to get the new env vars values.




回答2:


Instead of env() use \Config::get() or 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?



来源:https://stackoverflow.com/questions/39046560/laravel-5-2-envapp-env-does-not-work-in-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!