title: How to save in a polymorphic relationship in Laravel?
body: <p>I'm reading the tutorial* on how to define many-to-many polymorphic relationships in Laravel but it doesn't show how to save records with this relationship.</p>
  
  <p>In the their example they have</p>
  
  <pre><code>class Post extends Model
  {
      /**
       * Get all of the tags for the post.
       */
      public function tags()
      {
          return $this-&gt;morphToMany('App\Tag', 'taggable');
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class Tag extends Model
  {
      /**
       * Get all of the posts that are assigned this tag.
       */
      public function posts()
      {
          return $this-&gt;morphedByMany('App\Post', 'taggable');
      }
  
      /**
       * Get all of the videos that are assigned this tag.
       */
      public function videos()
      {
          return $this-&gt;morphedByMany('App\Video', 'taggable');
      }
  }
  </code></pre>
  
  <p>I've tried saving in different ways but the attempts that makes most sense to me is:</p>
  
  <pre><code>$tag = Tag::find(1);
  $video = Video::find(1);
  $tag-&gt;videos()-&gt;associate($video);
  
  or
  
  $tag-&gt;videos()-&gt;sync($video);
  </code></pre>
  
  <p>None of these are working. Can anyone give me a clue on what I could try?</p>
  
  <ul>
  <li><a href="https://laravel.com/docs/5.4/eloquent-relationships#many-to-many-polymorphic-relations" rel="noreferrer">https://laravel.com/docs/5.4/eloquent-relationships#many-to-many-polymorphic-relations</a></li>
  </ul>