Hi,
I have this code:
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->bigInteger('company_id')->unsigned();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->string('name');
$table->string('surname')->nullable();
$table->mediumText('description')->nullable();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->boolean('enable')->default(false);
$table->string('slug', 250);
$table->rememberToken();
$table->softDeletes();
$table->timestamps();
});
When I create new user or delete this user this migration work fine. Problem is when I soft deleted user ex [email protected] and then I try create new user [email protected] (when old was deleted).
My code to create to save user:
$validator = Validator::make(['email' => $adult->email],[
'email' => 'unique:users,email,NULL,id,deleted_at,NULL'
]);
if($validator->passes()){
/// codę to creation user
}
else{
echo 'This user exist';
}
When I run my code I have error:
"message": "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '[email protected]' for key 'users.users_email_unique' (Connection: mysql, SQL: insert into `users` (`name`, `surname`, `email`, `enable`, `password`, `email_verified_at`, `company_id`, `slug`, `updated_at`, `created_at`) values (\u0141ukasz, XXXX, [email protected], 1, /Tzqaigb0jSadFH8xJYqu, 2024-04-10 16:15:07, 1, xxxx-6, 2024-04-10 16:15:07, 2024-04-10 16:15:07))",
"exception": "Illuminate\Database\UniqueConstraintViolationException"
How can I repair it?
Please help me :)