title: Failed to insert multiple tags on Laravel
body: <p>I want to insert a Post record with multiple tags so here's my code in Post@store:</p>
  
  <pre><code>$post = Post::create(array(
              'title' =&gt; $request-&gt;title,
              'body' =&gt; $request-&gt;body,
              'user_id' =&gt; Auth::id(),
          ));
  
          if($post &amp;&amp; $request-&gt;tags)
          {
              $tagNames = explode(',', $request-&gt;tags);
              $tagIds = [];
              foreach($tagNames as $tagName)
              {
                  $tag = Tag::firstOrCreate(['name'=&gt;$tagName]);
                  if($tag)
                  {
                      $tagIds[] = $tag-&gt;id;
                  }
              }
  
              $post-&gt;tags()-&gt;attach($tagIds);
          }
  </code></pre>
  
  <p>but it give me an errors <code>"Call to a member function attach() on null"</code>. when i'm checked in mysql the tags is already in there but i can't find any entry on my post_tag tables. here's my post model:</p>
  
  <pre><code>class Post extends Model
  {
      protected $fillable = ['user_id','title','slug','body','tags','category_id','featured'];
  
      public function category()
      {
          return $this-&gt;belongsTo('App\Category');
      }
  
      public function tags()
      {
          $this-&gt;hasMany('App\Tag');
      }
  }
  </code></pre>