I need some clarification on the purpose of the php artisan optimize command.
Here’s my situation:
I have two MySQL databases — one for local development and one for testing. After setting up the testing environment, I noticed that it was not using the testing database and instead affected the local database. After correcting the configuration, it started working as expected. However, when I ran the php artisan optimize command, it reverted back to using the local database. Clearing the cache fixed the issue, and the testing environment started working again.
Could you help me understand why running the php artisan optimize command seems to reset my testing configuration?
@shariff You should not run the optimize command (or any of the *:cache commands) outside of production.
The optimize command isn’t “resetting” your configuration; it’s caching it to a file based on the values at that time. Which is why your tests will then start using your local database—because it’s reading your cached configuration, seeing the local configuration details, and using those
Please, clear your caches (php artisan optimize:clear) and never run any of those commands locally again.