Vansh Srivastava
Vansh Srivastava

Reputation: 1

Integrity constraint violation: 19 NOT NULL laravel

Illuminate\Database\QueryException

SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: users.password (SQL: insert into "users" ("name", "email", "username", "updated_at", "created_at") values (MADHUP KUMAR, [email protected], Vansh123, 2020-06-12 09:38:46, 2020-06-12 09:38:46))

http://127.0.0.1:8000/register

user.php model

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email','username','password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
         'password','remember_token',
    ];

create_user_table.php migration

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('email')->unique();
        $table->string('username')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });
}

RegisterController.php

protected function validator(array $data)
{
    return Validator::make($data, [
        'name' => ['required', 'string', 'max:255'],
        'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
        'username' => ['required', 'string', 'min:5','unique:users'],
        'password' => ['required', 'string', 'min:8', 'confirmed'],

    ]);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return \App\User
 */
protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'username' => $data['username'],
        'password' > Hash::make($data['password'])
    ]);
}

Upvotes: 0

Views: 548

Answers (2)

Nikhil Rauniyar
Nikhil Rauniyar

Reputation: 1

Here's the solution to this: Goto app>Models>User.php and add username to the fillable function.

    protected $fillable = [
    'name',
    'email',
    'password',
    'username',
];

Upvotes: 0

Adam Rodriguez
Adam Rodriguez

Reputation: 1856

You forgot the = in your array. In your create method change

'password' > Hash::make($data['password'])

To

'password' => Hash::make($data['password'])

Upvotes: 1

Related Questions