I'm upgrading Laravel to 5.2 from 5.1. When i refere to variable API_DOMAIN in .env file using $_ENV $_ENV['API_DOMAIN'] I get an error saying Undefined index: API_DOMAIN". Am I missing something here? should i do something after composer update?

  • Sim
    Sim 回复


    Lets use your API_DOMAIN as an example:



    config/api.php for example

    return [
        'domain' => env('API_DOMAIN'),

    Now you can use the config helper to use this variable in your application:

    $value = config('api.domain');

    You should never use the env() helper outside of config files, because when you cache your config, env() will return null.

  • ~昵称
    ~昵称 回复

    Try env helper instead, env('API_DOMAIN')