Laravel user registration 5.4?

Asked

Viewed 147 times

1

I am trying to register a user in the table and is returning the following error:

SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES) (SQL: select count(*) as aggregate fromuserswhereemail= ****@gmail.com)

My connection code:

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'teste'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', '/tmp/mysql.sock'),
            'charset' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

My Controller:

protected function validator(array $data)
    {
        return Validator::make($data, [         
            'name' => 'required|max:255',
            'user' => 'required|max:100',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6|confirmed',
        ]);
    }


    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'user' => $data['user'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
    }

My Model:

protected $fillable = [
        'name', 'user', 'email', 'password',
    ];
  • 1

    Changed settings in file .env at the root of your project?

  • 1

    Worse than not, how does this configuration?

1 answer

3


You have a file at the root of your project .env, changes the settings DB_* with your database settings:

Exactly those:

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database.sqlite
DB_USERNAME=homestead
DB_PASSWORD=secret

Complete file:

APP_ENV=local
APP_KEY=base64:r2byh5hoHbpxe6CdxRohGwueB8FFkQqma+XNR026t4A=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database.sqlite
DB_USERNAME=homestead
DB_PASSWORD=secret

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

Browser other questions tagged

You are not signed in. Login or sign up in order to post.