title: Laravel attach pivot data without errors
body: <p>I a have pivot table and a relation on model Product:</p>
  
  <pre><code>public function product_bodies()
  {
      return $this-&gt;belongsToMany(static::class, 'product_bodies')-&gt;withPivot('product_id', 'product_body_id');
  }
  </code></pre>
  
  <p>In the controller when I want to attach data:</p>
  
  <pre><code>    $products = ['sadasdasd', 'asdasda', 'asdasd', 'asdasd']; //for column product_body_id
      $product = Product::create($request-&gt;all());
  
      $product-&gt;product_bodies()-&gt;attach($products);
  </code></pre>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>General error: 1364 Field 'product_body_id' doesn't have a default
    value</p>
  </blockquote>
  
  <p>If I do this:</p>
  
  <pre><code>public function product_bodies()
  {
      return $this-&gt;belongsToMany(static::class, 'product_bodies', 'product_id', 'product_body_id')-&gt;withPivot('product_id', 'product_body_id');
  }
  </code></pre>
  
  <p>Then all works well. But then I can't get pivot data with:</p>
  
  <pre><code>$product-&gt;product_bodies;
  </code></pre>
  
  <p>I get empty items..</p>
  
  <p>How can I fix this problem?</p>
  
  <p>Table <code>product_bodies</code> has 3 columns:</p>
  
  <ul>
  <li>id</li>
  <li>product_id</li>
  <li>product_body_id</li>
  </ul>
  
  <p>In product_body_id I pass strings.</p>