title: Laravel 5: SQLSTATE[23000]: Integrity constraint violation
body: <p>I have a form with the following fields: name, fullname, description, email, password, state, city (filled through Ajax when the state is chosen) and photo (a image upload).
  Here's my schema:</p>
  
  <pre><code>public function up()
  {
      Schema::create('states', function(Blueprint $table)
      {
          $table-&gt;increments('id');
          $table-&gt;string('acronym');
          $table-&gt;string('name');
      });
  
      Schema::create('cities', function(Blueprint $table)
      {
          $table-&gt;increments('id');
          $table-&gt;string('name');
          $table-&gt;integer('state_id')-&gt;unsigned();
          $table-&gt;foreign('state_id')-&gt;references('id')-&gt;on('states');
      });
  
      Schema::create('users', function(Blueprint $table)
      {
          $table-&gt;increments('id');
          $table-&gt;string('name');
          $table-&gt;string('fullname');
          $table-&gt;string('photo');
          $table-&gt;text('description');
          $table-&gt;string('email');
          $table-&gt;string('password', 60);
          $table-&gt;integer('city_id')-&gt;unsigned();
          $table-&gt;foreign('city_id')-&gt;references('id')-&gt;on('cities');
          $table-&gt;rememberToken();
      });
  }
  </code></pre>
  
  <p>My problem is that when I press the submit button, the following error message appears:</p>
  
  <p>SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (<code>yearbook</code>.<code>users</code>, CONSTRAINT <code>users_city_id_foreign</code> FOREIGN KEY (<code>city_id</code>) REFERENCES <code>cities</code> (<code>id</code>)) (SQL: insert into <code>users</code> (<code>name</code>, <code>description</code>, <code>email</code>) values (Gabriel, Description, email@gmail.com))</p>
  
  <p>So the problem is related to the city_id being a foreign key (the 'value' attribute from the option at the form is the id). Fro exemple:</p>
  
  <pre><code>&lt;option value="281"&gt;Abaíra&lt;/option&gt;
  </code></pre>
  
  <p>But when I try to insert through phpmyadmin, it inserts with no errors.</p>
  
  <p><strong>So what could be the problem?</strong></p>
  
  <p>Here's my save method at the controller:</p>
  
  <pre><code>public function saveRegister()
  {
      $rules = array(
          'name' =&gt; 'required',
          'description' =&gt; 'required',
          'fullname' =&gt; 'required',
          'email' =&gt; 'required',
          'password' =&gt; 'required',
          'state' =&gt; 'required',
          'city' =&gt; 'required',
          'photo' =&gt; 'required',
          'photo' =&gt; 'image|max:3000000',
      );
      $val = \Validator::make(\Input::all(), $rules);
  
      if($validar-&gt;fails()){
          return redirect('register')-&gt;withErrors($val);
      } else {
          $user = new User(array(
              'name' =&gt; \Input::get('name'),
              'description' =&gt; \Input::get('description'),
              'fullname' =&gt; \Input::get('fullname'),
              'email' =&gt; \Input::get('email'),
              'city_id' =&gt; \Input::get('city'),
          ));
          $user-&gt;timestamps = false;
          $user-&gt;save();
          return redirect('register')-&gt;with('message', 'User saved!');
  
      }
  }
  </code></pre>
  
  <p>Edit: fixed city_id at saveRegister() method.</p>