Why is there 2 APP Key in Laravel? .env and config

2019-04-29 11:54发布

问题:

I installed Laravel 5 via composer and after the installation the App Key was generated automatically. I went to .env file and I could see the APP_KEY there. However, I also noticed that there is another APP_KEY inside config/app.php like this:

'key' => env('APP_KEY', 'SomeRandomString'),
'cipher' => 'AES-256-CBC',

My newbie questions are:

1) Why is there App keys in 2 different locations?

2) When App Key was generated, why didnt it update the config/app.php file as well?

3) Do I need to manually paste the .env App key into the config/app.php file too or will that be not necessary as long as .env has it there?

4) During future updates, do I need to keep adding the App key into app.php file? Meaning, would it get reseted during updates?

回答1:

The value set in config/app.php is used if there is no value in the .env file. If you have set the app key in the .env file, the second argument in app.php is ignored.