title: Insert data to a pivot table in laravel
body: <p>I have 3 tables: <code>posts</code>, <code>tags</code>, <code>post_tag</code>.</p>
  
  <p>Each <code>Post</code> has many tags so I use <code>hasMany</code> method for them. But when I choose for example 3 tags in my dropdown list, I can't add them to <code>post_tag</code> and as the result I can't select and show each post's tags. </p>
  
  <p>My <code>Post</code> model:</p>
  
  <pre><code> class Post extends Eloquent{
   public function tag()
           {
             return  $this-&gt;hasMany('Tag');
           }
      }
  </code></pre>
  
  <p>My <code>Tag</code> model:</p>
  
  <pre><code>class Tag extends Eloquent{
   public function post()
           {
             return  $this-&gt;belongsToMany('Post');
           }
  </code></pre>
  
  <p>}</p>
  
  <p>And my <code>postController</code>:</p>
  
  <pre><code>class postController extends BaseController{
  
  public function addPost(){
  
      $post=new Post;
  
      $post_title=Input::get('post_title');
      $post_content=Input::get('post_content');
      $tag_id=Input::get('tag');
  
      $post-&gt;tag()-&gt;sync($tag_id);
      $post-&gt;save();
  </code></pre>
  
  <p>I expect to save this <code>post_id</code> save to <code>post_tag</code> table with its tag ids,
  but it doesn't work. Thanks for your time.</p>