title: Laravel / PHP - Advanced polymorphic relationship
body: <p>In my web application, users can upload <code>documents</code> or <code>emails</code> to <code>channels</code>. </p>
  
  <p>A channel can furthermore then have <code>document_tags</code> and <code>email_tags</code>, that <strong>all</strong> uploaded documents/emails automatically should inherit. </p>
  
  <p>Furthermore, <code>document_tags</code> and <code>email_tags</code> <strong>will</strong> have different descriptions: <code>tag_descriptions</code>. So for example if we have a document, uploaded to a channel that have the tags: <code>animals (id = 1)</code> and <code>pets (id = 2)</code></p>
  
  <ol>
  <li><code>Document #55</code> is upladed to <code>Channel #8</code>.</li>
  <li><code>Document #55</code> will automatically inherit the tags, that have <code>document_tags.channel_id = 55</code> (this can be accessed with the following relationship: <code>$channel-&gt;documenttags</code>). In this case <code>animals</code> and <code>pets</code>. </li>
  <li>Now the user should be able to set an unique description for the tegs <code>animals</code> and <code>pets</code> in <code>tag_descriptions</code>, for example:</li>
  </ol>
  
  <p><code>tag_descriptions</code></p>
  
  <pre><code>id | taggable_type   | taggable_id  | typeable_type | typeable_id | description
  1  | App\DocumentTag | 1            |  App\Document | 55          | My unique description for animals. 
  2  | App\DocumentTag | 2            |  App\Document | 55          | My unique description for pets.
  </code></pre>
  
  <p>Now in above database design the uploaded <code>document #55</code>, have the tags: <code>animals</code> and <code>pets</code> associated, but further these two tags have a unique description, that is unique for the specific <strong>document</strong>.</p>
  
  <p>If I upload another document, or an email (let's say <code>email #20</code>), then I imagine it will look like:</p>
  
  <p><code>tag_descriptions</code>:</p>
  
  <pre><code>id | taggable_type   | taggable_id  | typeable_type | typeable_id | description
  1  | App\DocumentTag | 1            |  App\Document | 55          | My unique description for animals. 
  2  | App\DocumentTag | 2            |  App\Document | 55          | My unique description for pets.
  3  | App\EmailTag    | 1            |  App\Email    | 20          | Another unique description for animals. 
  4  | App\EmailTag    | 2            |  App\Email    | 20          | Yet another unique description for pets.
  </code></pre>
  
  <p>Now the <code>email #20</code> also have the tags <code>animals</code> and <code>pets</code>, but in this case, the user can set unique descriptions for the tags.</p>
  
  <p><strong>Now my question is:</strong></p>
  
  <p>Is above design doable, and is it considered best practice in Laravel / PHP? I am a bit unsure how to structure the code, because the <code>TagDescription</code> model will suddenly have <strong>two polymorphic</strong> relationships (<code>taggable</code> and <code>typeable</code>), and I cannot find anything in the documentation that this is supported.</p>
  
  <p>Furthermore, I am unsure if I can use the above design to access the unique descriptions through the specific uploaded document, such as:</p>
  
  <pre><code>//In my Document.php model:
  public function tagdescriptions()
  {
      return $this-&gt;morphMany(TagDescription::class, 'typeable');
  }
  </code></pre>
  
  <p>Then use it like: <code>$document-&gt;tagdescriptions</code>.</p>
  
  <p>Last but not least - I am a bit unsure how to save the unique tag description for the specific taggable_id / taggable_type and unique email/document. (typeable_id and typeable_type).</p>