title: How to insert record with many belongsTo relations in Laravel Eloquent
body: <p>I am trying to insert record in Eloquent way.</p>
  
  <p>It is clear in basic cases. For example if I have a Blog with Posts and each post belongs to a User I can do this:</p>
  
  <pre><code>$post = new Post;
  $post-&gt;content = 'Post content';
  $user-&gt;posts()-&gt;save($post);
  </code></pre>
  
  <p>But how should I do this if my Post belongs to User, Category and Group at the same time?</p>
  
  <p>My first idea was to do it this way:</p>
  
  <pre><code>$post = new Post;
  $post-&gt;content = 'Post content';
  $user-&gt;posts()-&gt;save($post);
  $group-&gt;posts()-&gt;associate($post);
  $cat-&gt;posts()-&gt;associate($post);
  </code></pre>
  
  <p>But it doesn't work, because group id and category id are null when I save it to the DB and it is not allowed.</p>
  
  <p>What I am doing now is:</p>
  
  <pre><code>$post = new Post;
  $post-&gt;content = 'Post content';
  $post-&gt;group = $group-&gt;id;
  $post-&gt;category = $cat-&gt;id;
  $user-&gt;posts()-&gt;save($post);
  </code></pre>
  
  <p>But I don't think it is the right way.</p>
  
  <p>Could someone point me in the right direction?</p>