title: "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
body: <p>I am submitting a form with AJAX and in the network I am getting this error.</p>
  
  <pre><code>"SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'k@t.com' for key 'users_email_unique' (SQL: insert into `users` (`name`, `email`, `active`, `verify`, `user_type`, `password`) values (K, k@t.com, 2, , 3, $2y$10$FiwHZB1VKWo0skjrCn/16epQq5aqfwdQ055PZLebaK4XEyQFNuDai))"
  </code></pre>
  
  <p>I am using Laravel 5.6 and also, migrations. Here is the migration for this table. </p>
  
  <pre><code>    Schema::create('users', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('name');
          $table-&gt;string('email')-&gt;unique();
          $table-&gt;string('password');
          $table-&gt;tinyInteger('user_type');
          $table-&gt;tinyInteger('active');
          $table-&gt;rememberToken();
          $table-&gt;timestamps();
          $table-&gt;index('user_type');
          $table-&gt;index('active');
      });
  </code></pre>
  
  <p>And, this is my Controller's function.</p>
  
  <pre><code>public function teacherApply(Request $request)
  {
  
      if (Input::get()) {
  
          $data = Input::get();
  
          $email_check = User::where(['email' =&gt; $data['email'], 'active' =&gt; 1])-&gt;first();
  
          if (!empty($email_check))
          {
              return ["status" =&gt; 3, "message" =&gt; "Email already registered"];
          }
          else
          {
  
             $required_points = [
  
                 'name'                   =&gt;     'required',
  
                 'firstName'              =&gt;     'required',
  
                 'lastName'               =&gt;     'required',
  
                 'email'                  =&gt;     'required',
  
                 'contact'                =&gt;     'required',
  
                 'password'               =&gt;     'required',
  
                 'degree'                 =&gt;     'required',
  
                 'field'                  =&gt;     'required',
  
                 'about'                  =&gt;     'required'
  
             ];
  
          $validator = Validator::make($request-&gt;all(), $required_points);
  
          if ($validator-&gt;fails()) {
  
              return response()-&gt;json(['errors'=&gt;$validator-&gt;errors(),'status' =&gt; 2]);
  
          }
  
          $name = $data['name'];
  
          $file_name    =    'Empty';
  
          $file         =    Input::file('image');
  
          if(!empty($file))
          {
  
          $destination   =    base_path('public/pmc_assets/teacher-samples');
  
          $file_name     =    upload_file($file, $destination);
  
          }
  
          $userID = User::insertGetId([
  
              'name'          =&gt;     $name,
  
              'email'         =&gt;     $data['email'],
  
              'active'        =&gt;     2,
  
              'verify'        =&gt;     '',
  
              'user_type'     =&gt;     config('constant.teacher'), // Teacher
  
              'password'      =&gt;     bcrypt($data['password']),
          ]);
  
          TeacherRequests::insert([
  
              'name'          =&gt;     $data['firstName']." ".$data['lastName'],
  
              'phone'         =&gt;     $data['contact'],
  
              'skype'         =&gt;     $data['skype'],
  
              'user_id'       =&gt;     $userID,
  
              'degree_type'   =&gt;     $data['degree'],
  
              'degree_field'  =&gt;     $data['field'],
  
              'about'         =&gt;     $data['about'],
  
              'sample'        =&gt;     $file_name,
  
              'resume'        =&gt;     '',
  
              'active'        =&gt;     2,
  
              'approved'      =&gt;     0,
  
              'created_at'    =&gt;     Carbon::now()
  
          ]);
  
          //send_to_flock_channel($name,"Manual","Teacher");
  
          return ["status"=&gt; 1, "user_id" =&gt; $userID, "email" =&gt; $data['email']];
  
      }
  
      }
  
      return view('teacher.apply_teacher');
  }
  </code></pre>
  
  <p>My file is uploading successfully and also, the data is inserted in the database, but still, I am getting this error. This is not affecting me, but want to solve it?</p>