title: SQLSTATE[22007] Invalid datetime format 1366 Incorrect integer value:a field for column
body: <p>After login a user, The user enters this skills form, selects the skills.</p>
  <p><a href="https://i.stack.imgur.com/Rxad6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Rxad6.png" alt="skills" /></a></p>
  <p>A user can enter multiple skills, and save in database.</p>
  <p>The field of name</p>
  <ul>
  <li>skill_name</li>
  <li>level</li>
  <li>user_id</li>
  </ul>
  <p>And in table</p>
  <ul>
  <li>skill_name</li>
  <li>level</li>
  <li>user_id</li>
  </ul>
  <p>I don't know if the <code>skills</code> and <code>skill_user</code> table should be, or not, I don't know.</p>
  <p>What would you do if you were me?</p>
  <p>Can you show me the cleanest coding?</p>
  <p>I'm trying to make a relationship between 3 tables users and skills and skill_user. My schema in skills table is:</p>
  <p>table</p>
  <pre><code>public function up()
  {
      Schema::create('skills', function (Blueprint $table) {
          $table-&gt;bigIncrements('id');
          $table-&gt;bigInteger('user_id')-&gt;unsigned();
          $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users')-&gt;onDelete('cascade');
          $table-&gt;string('skill_name');
          $table-&gt;smallInteger('level');
          $table-&gt;timestamps();
      });
  
      Schema::create('skill_user', function (Blueprint $table) {
          $table-&gt;bigIncrements('id');
          $table-&gt;bigInteger('skill_id')-&gt;unsigned()-&gt;nullable();
          $table-&gt;foreign('skill_id')-&gt;references('id')-&gt;on('skills')-&gt;onDelete('cascade');
          $table-&gt;bigInteger('user_id')-&gt;unsigned()-&gt;nullable();
          $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users')-&gt;onDelete('cascade');
          $table-&gt;unique(['skill_id' , 'user_id']);
          $table-&gt;string('skill_name');
          $table-&gt;smallInteger('level');
      });
  }
  </code></pre>
  <p>Controller.php</p>
  <pre><code>    $user-&gt;skills()-&gt;detach();
      if ($request-&gt;skill_name) {
          foreach ($request-&gt;skill_name as $key =&gt; $skill_name) {
              $user-&gt;skills()-&gt;attach($skill_name, [
                  'user_id' =&gt; auth()-&gt;id(),
                  'level' =&gt; $request-&gt;level[0],
                  'skill_name' =&gt; $request-&gt;skill_name[0],
              ]);
          }
      }
  </code></pre>
  <p>blade</p>
  <pre><code>showDynamicExperimental();
  function showDynamicExperimental()
  {
      let html = '' +
          '@foreach(auth()-&gt;user()-&gt;skills as $skill)\n'+
          '&lt;div class=&quot;col-md-6 position-relative&quot;&gt;\n' +
          '&lt;i class=&quot;fas fa-times text-danger position-absolute&quot;&gt;&lt;/i&gt;' +
          '&lt;div class=&quot;row&quot;&gt;\n' +
          '&lt;div class=&quot;col-md-8&quot;&gt;\n' +
          '&lt;div class=&quot;form-group&quot;&gt;\n' +
          '&lt;label for=&quot;skill_name&quot;&gt;skill_name&lt;/label&gt;\n' +
          '&lt;input type=&quot;text&quot; id=&quot;skill_name&quot; name=&quot;skill_name[]&quot; class=&quot;form-control&quot; value=&quot;{{ $skill-&gt;skill_name }}&quot;&gt;\n' +
          '&lt;/div&gt;\n' +
          '&lt;/div&gt;\n' +
          '&lt;div class=&quot;col-md-4&quot;&gt;\n' +
          '&lt;div class=&quot;form-group&quot;&gt;\n' +
          '&lt;label for=&quot;level&quot;&gt;level&lt;/label&gt;\n' +
          '&lt;select class=&quot;form-control&quot; id=&quot;level&quot; name=&quot;level[]&quot;&gt;\n' +
          '&lt;option value=&quot;1&quot; {{ $skill-&gt;level == 1 ? 'selected' : '' }}&gt;★☆☆☆☆&lt;/option&gt;\n'+
          '&lt;option value=&quot;2&quot; {{ $skill-&gt;level == 2 ? 'selected' : '' }}&gt;★★☆☆☆&lt;/option&gt;\n'+
          '&lt;option value=&quot;3&quot; {{ $skill-&gt;level == 3 ? 'selected' : '' }}&gt;★★★☆☆&lt;/option&gt;\n'+
          '&lt;option value=&quot;4&quot; {{ $skill-&gt;level == 4 ? 'selected' : '' }}&gt;★★★★☆&lt;/option&gt;\n'+
          '&lt;option value=&quot;5&quot; {{ $skill-&gt;level == 5 ? 'selected' : '' }}&gt;★★★★★&lt;/option&gt;\n'+
          '&lt;/select&gt;\n'+
          '&lt;/div&gt;\n' +
          '&lt;/div&gt;\n' +
          '&lt;/div&gt;\n' +
          '&lt;/div&gt;\n ' +
          '@endforeach';
      $('#showExperimental').append(html);
  }
  </code></pre>
  <p>User.php</p>
  <pre><code>public function skills()
  {
      return $this-&gt;belongsToMany(Skill::class)-&gt;withPivot('skill_name');
  }
  </code></pre>
  <p>I get this error.</p>
  <p><a href="https://i.stack.imgur.com/oh6nz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oh6nz.png" alt="error" /></a></p>