简体   繁体   English

Laravel 5.1 SQLSTATE [23000]:违反完整性约束错误

[英]Laravel 5.1 SQLSTATE[23000]: Integrity constraint violation error

On registering with new email, I can successfully register the new user, but when I try to make a validation rule to restrict an existing email from signup, instead of giving validation error message, its giving me Integrity constraint violation error , 在注册新电子邮件时,我可以成功注册新用户,但是当我尝试制定validation rule以限制现有电子邮件无法注册时,而不是给出验证错误消息,它给了我Integrity constraint violation error

here is my controller 这是我的controller

 public function postRegister(Request $request){
        $v = validator::make($request->all(), [
            'first_name' => 'required|max:30',
            'last_name' => 'required|max:30',
            'email' => 'required|unique:users|email',
            'mobile' => 'required|min:10',
            'password' => 'required|min:8',
            'confirm_password' => 'required|same:password'
        ]);

        if ($v->fails())
        {
            return redirect()->back()
                ->withErrors($v->errors())
                ->withInput(Input::except('password', 'confirm_password'));
        }



        else{

            // validation successful ---------------------------

            /*
            add data to database
             */

} }

and this is my migration 这是我的migration

public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('first_name', 80);
            $table->string('last_name', 80);
            $table->string('email')->unique();
            $table->string('mobile',80);
            $table->string('password', 60);
            $table->boolean('confirmed')->default(0);
            $table->string('confirmation_code')->nullable();
            $table->float('amount', 80);
            $table->rememberToken();
            $table->timestamps();
        });
    } 

How can I fix this error? 如何解决此错误? Any help appreciated. 任何帮助表示赞赏。

Should be: 应该:

 if ($v->fails())
    {
        return redirect()->back()
            ->withErrors($v->messages()) //Not errors
            ->withInput(Input::except('password', 'confirm_password'));
    }

If you read the documentation of Validators. 如果您阅读了验证程序的文档。

First Parameter: Is for Inputs 第一个参数:用于输入

Second Parameter: Is for Rules 第二个参数:用于规则

Third Parameter: Is for custom Messages 第三个参数:用于自定义消息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQLSTATE [23000]:违反完整性约束:1048 Laravel 4 - SQLSTATE[23000]: Integrity constraint violation: 1048 Laravel 4 SQLSTATE [23000]:违反完整性约束:在Laravel 5.2中 - SQLSTATE[23000]: Integrity constraint violation: in Laravel 5.2 Laravel 5:SQLSTATE [23000]:违反完整性约束 - Laravel 5: SQLSTATE[23000]: Integrity constraint violation SQLSTATE [23000]:违反完整性约束:在Laravel 5上 - SQLSTATE[23000]: Integrity constraint violation: on Laravel 5 laravel 8 播种,SQLSTATE[23000]:违反完整性约束: - laravel 8 seeding , SQLSTATE[23000]: Integrity constraint violation: SQLSTATE [23000]:违反完整性约束 - SQLSTATE[23000]: Integrity constraint violation Laravel 5:SQLSTATE [23000]:违反完整性约束,外键约束失败 - Laravel 5: SQLSTATE[23000]: Integrity constraint violation, foreign key constraint fails Laravel 7 错误消息:'SQLSTATE [23000]:完整性约束违规:19 NOT NULL 约束失败:profiles.Z572D4E421E5E6B9BC11D815E8A02712 - Laravel 7 Error message: 'SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: profiles.url Laravel 6 - SQLSTATE [23000]:违反完整性约束:1048 列不能是 null - Laravel 6 - SQLSTATE[23000]: Integrity constraint violation: 1048 Column cannot be null Laravel 5.8 SQLSTATE[23000]:违反完整性约束:1048 - Laravel 5.8 SQLSTATE[23000]: Integrity constraint violation: 1048
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM