title: Laravel: How to define belongsTo in a MorphPivot?
body: <p>In my project there is a Many-to-Many polymorphic relationship (Many instances of a model called Package (morphedByMany) can contain many different content types (each MorphedToMany).</p>
  
  <p>I've created a pivot table containing some additional fields that I'll need to access and query by, and so I've decided that the best thing would be to create a Pivot model by extending the MorphPivot.</p>
  
  <p>Querying is now easy enough, however, I can't access the content through a relation (which I can do if i query the App\Packages::findOrFail(1)->contentType()). I know I should declare that the pivot belongsTo the contentType, but I'm not sure how to go about it seeing as it could belong to any of the morphed contentTypes.</p>
  
  <p><strong>EDIT</strong>
  <strong>Code blocks as requested</strong></p>
  
  <p>Content1</p>
  
  <pre><code>class Song extends Model
  {
  
    public function packages()
    {
        return $this-&gt;morphToMany('App\Package', 'packageable')-&gt;withPivot('choice')-&gt;using('App\PackageContent');
    }
  </code></pre>
  
  <p>Content2</p>
  
  <pre><code>class Video extends Model
  {
  
    public function packages()
    {
        return $this-&gt;morphToMany('App\Package', 'packageable')-&gt;withPivot('choice')-&gt;using('App\PackageContent');
    }
  </code></pre>
  
  <p>Package</p>
  
  <pre><code>class Package extends Model
  {
    public function songs()
    {
        return $this-&gt;morphedByMany('App\Song', 'packageable')-&gt;withPivot('choice')-&gt;using('App\PackageContent');
    }
  
    public function videos()
    {
        return $this-&gt;morphedByMany('App\Video', 'packageable')-&gt;withPivot('choice')-&gt;using('App\PackageContent');
    }
  
  </code></pre>
  
  <p>MorphPivot</p>
  
  <pre><code>use Illuminate\Database\Eloquent\Builder;
  use Illuminate\Database\Eloquent\Relations\MorphPivot;
  
  class PackageContent extends MorphPivot
  {
    protected $table = 'packageables';
  </code></pre>
  
  <p>Pivot table migration</p>
  
  <pre><code>    public function up()
      {
        Schema::create('packageables', function (Blueprint $table) {
          $table-&gt;integer('package_id');
          $table-&gt;integer('packageable_id');
          $table-&gt;string('packageable_type');
          $table-&gt;integer('choice');
        });
      }
  </code></pre>