Conflict database when Multiple Laravel Projects on single machine or laravel not reading .env file

别说谁变了你拦得住时间么 提交于 2019-12-05 10:27:14

You have specified to use database_project_1 in Project 2's config/database.php:

'database' => env('DB_DATABASE', 'database_project_1'),

So if ever env('DB_DATABASE') does not return a value , the default of database_project_1 will be used. That can happen depending on caching, as described in a few questions here on SO: example 1, example 2, example 3.

If it is a caching issue, you can try to fix that by some combination of the following (varies between installs and versions):

php artisan config:clear
php artisan cache:clear
composer dump-autoload
// restart your web server

But surely the simplest fix would be to just use the correct default value in your Project 2 config/database.php:

'database' => env('DB_DATABASE', 'database_project_2'),

On production we should use cache for config and should not use env('xxx') at runtime. If you like to use env function, I suggest that use different name for each project

DB_DATABASE_PROJECT1=pro1
DB_USERNAME_PROJECT1=user1
DB_PASSWORD_PROJECT1=xxx

and

'database' => env('DB_DATABASE_PROJECT1', 'project_1'),
...

cache

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