Search code examples
phpmysqldatabaselaravellaravel-artisan

Laravel .env file returns wrong data


I've been trying to get data from my database in laravel 5.7.3, but it seems to be using the wrong database name, username and password as it returns this error:

SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES) (SQL: select * from `tasks`)

My .env file database section is also according to my needs and set like this:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mrdb
DB_USERNAME=root
DB_PASSWORD=

PS: My app environment is still local. I can also migrate and put in data into database with artisan tinker without issues, but cannot just fetch data from the database.

The only way it gets to work is to change config/database.php mysql section to my parameters, which I believe it isn't just right.

Why is the .env not wanting the change when the database is called?


Solution

  • Laravel uses caching to speed up your sites loading times, one of the things laravel caches is the config files located in the config/ directory. Most of these files do have references to the .env file by using the env() helper function.

    One can create a config cache by using php artisan config:cache which will then be stored in bootstrap/cache/config.php.

    To remove this specific cache you can use php artisan config:clear, to clear all cache use php artisan cache:clear.