Reputation: 379
I was trying to implement basic user registration & login using 'auth'. I am able to create the migrations and the tables are already created in the database as well.
When I fill up the registration details such as Name, Email, Password & Confirm Password and hit register, I'm landing up in this error:
This is the code in my .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=townbakery
DB_USERNAME=root
DB_PASSWORD=12345678!
I've added any other code or have made any other changes except changing the Route web.php as
Route::get('/', function () {
return view('auth.login');
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Please help me where I've gone wrong. This is the first application I'm working on after learning laravel basics.
Database.php looks like:
mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Here is my User.php model:
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
Upvotes: 1
Views: 7258
Reputation: 131
I was facing the same issue of SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO). I resolved the problem by just creating a new user with password into mysql db and updated the .env file accordingly. I came out that the problem was resolved.
Upvotes: 0
Reputation: 2800
I encountered this error and solved. First try:
php artisan config:cache
php artisan config:clear
php artisan cache:clear
than, restart your server:
php artisan serve
Before the solution, I tried to write username, password and database name as hard coded in database.php. After I changed username and password, it was trying to find a database called laravel. It's clear that this is related with the first config file .env.example more clearly, it's related with config cache. So delete all possible cache combinations possible.
Upvotes: 1
Reputation: 17205
One last possibility would be that your server is forcing the value of the env variable DB_PASSWORD
ether through Vhost or .htaccess
To verify this, try changing your .env
variable to DB_T_PASSWORD=12345678!
and dont forget to change it in database.php
config file 'password' => env('DB_T_PASSWORD', ''),
Upvotes: 2