nanobox-quickstarts / nanobox-laravel

Quickstart for Laravel with Nanobox
https://guides.nanobox.io/php/laravel/
Mozilla Public License 2.0
10 stars 7 forks source link

env() function should be used to avoid undefined vars #3

Closed cossou closed 7 years ago

sanderson commented 7 years ago

@cossou, does the env() helper function pull in global environment variables or only those defined in the .env file?

cossou commented 7 years ago

@sanderson it pulls from both sources (not sure which one has priority).

Laravel uses: https://github.com/vlucas/phpdotenv

sanderson commented 7 years ago

Perfect. I had read conflicting statements about that. I should've gone straight to the source :smile:. I wonder if we should also include the default DB_ keys Laravel includes in the .env file as fallbacks. Would this work or is the env() function expecting a literal string as the default value?

'host' => env('DATA_DB_HOST', 'DB_HOST'),
'port' => '3306',
'database' => 'gonano',
'username' => env('DATA_DB_USER', 'DB_USERNAME'),
'password' => env('DATA_DB_PASS', 'DB_PASSWORD'),
cossou commented 7 years ago

No, that wouldn't work.

The second value passed to the env function is the "default value". This value will be used if no environment variable exists for the given key.

in https://laravel.com/docs/5.3/configuration#environment-configuration

I guess you could env('DATA_DB_USER', env('DB_USERNAME')) but it looks ugly 😭

sanderson commented 7 years ago

Since the quickstart is designed to work within the context of Nanobox, I think its fine that we don't pass in default values. The single values will always work inside Nanobox. If somebody were to use Laravel outside of Nanobox, I don't think they'd use this repo 😉 .

sanderson commented 7 years ago

Thanks @cossou!