Laravel: SQLSTATE[28000] [1045] Access denied for user 'homestead'@'localhost' Laravel: SQLSTATE[28000] [1045] Access denied for user 'homestead'@'localhost' laravel laravel

Laravel: SQLSTATE[28000] [1045] Access denied for user 'homestead'@'localhost'


I tried to make changes to database.php file present within config folder it looks something like this

'default' => 'mysql',.......'mysql' => [            'driver'    => 'mysql',            'host'      => env('DB_HOST', 'localhost'),            'database'  => env('DB_DATABASE', 'sample'),            'username'  => env('DB_USERNAME', 'root'),            'password'  => env('DB_PASSWORD', ''),            'charset'   => 'utf8',            'collation' => 'utf8_unicode_ci',            'prefix'    => '',            'strict'    => false,        ],

I am not using any VM, I am using my local machine, with the database user as root and password a null.

I have also changed my .env file and it looks something like this:

APP_ENV=localAPP_DEBUG=trueAPP_KEY=zLzPMzs5W4FNNuguTmbG8M0iFqhIVnsPDB_HOST=localhostDB_DATABASE=sampleDB_USERNAME=rootDB_PASSWORD=nullCACHE_DRIVER=fileSESSION_DRIVER=fileQUEUE_DRIVER=syncMAIL_DRIVER=smtpMAIL_HOST=mailtrap.ioMAIL_PORT=2525MAIL_USERNAME=nullMAIL_PASSWORD=null

Even after doing all the changes when I try to register using the registration form that is shipped with laravel, I try to add a user to my database I get the following error

laravel database connection error

After doing all the changes I cleared the cache and loaded it again and it seems to work for me now!if any one is also facing the same issue just run the following commands

php artisan cache:clearphp artisan config:cache


I figured it out :) Had to chance the .env file :)

Is there any changes in the schemaes?

Shouldn't this work:

public function up(){    // Create table with columns    Schema::create('users', function($table) {        $table->increments('id');        $table->string('username');        $table->string(Hash::make('password'));        $table->string('firstname');        $table->string('lastname');        $table->string('email')        $table->string('role');        $table->timestamps();    }); }/** * Reverse the migrations. * * @return void */public function down(){    // Insert table to database    Schema::drop('users');}


Try to check out the ".env" file in your root directory. These values are taken first. Yours are just the defaults if there are none given in the .env file.

DB_CONNECTION=mysql DB_HOST=127.0.0.1DB_PORT=3306DB_DATABASE=Your_Database_NameDB_USERNAME=Your_UserNameDB_PASSWORD=Your_Password