title: Retrieve polymorphic model instances
body: <p>Using <strong>Laravel 5.1</strong>, I'm trying to create a dynamic table where I can associate multiple item types with a <code>module</code>. I went with a <a href="https://laravel.com/docs/5.1/eloquent-relationships#polymorphic-relations" rel="nofollow">Polymorphic</a> table and set the <code>morphable_ids</code> and <code>morphable_types</code> per module as such:</p>
  
  <pre><code>id  module_id morphable_id morphable_type
  1       1          1       App/Enemy
  2       2          2       App/Enemy
  3       3          1       App/Item
  </code></pre>
  
  <p>I get my modules through associated <code>tasks</code>, aka <code>modules</code> are eager loaded in with tasks. When I drill down into my task from the API call, and check <code>module_items</code>, it shows the literal <code>morphable_id</code>/<code>morphable_type</code> rather than the <code>App\Enemy</code> or <code>App\Item</code> instances I was looking for:</p>
  
  <pre><code>more task obj properties...
  "module":{
     "id" : 1
     "module_items":[
        {
          "id": 3,
          "module_id": "3",
          "morphable_id": "1",
          "morphable_type": "App/Item"
        }
     ]
   }
  </code></pre>
  
  <p>So my question is, how can I actually retrieve the polymorphic model instance (like, I retrieve <code>App\Item</code> of id <code>1</code> for module <code>1</code>)?</p>
  
  <p>Here is some more information:</p>
  
  <p><strong>Models:</strong></p>
  
  <p>Task: loads with modules</p>
  
  <pre><code>class Task extends Model
  {
  
      protected $with = ['module'];
  
  
      public function module()
      {
          return $this-&gt;belongsTo(Module::class);
      }
  }
  </code></pre>
  
  <p>Module</p>
  
  <pre><code>class Module extends Model
  {
      protected $with = ['module_items'];
  
      public function task()
      {
          return $this-&gt;belongsTo(Task::class);
      }
  
      public function module_items()
      {
          return $this-&gt;hasMany(ModuleItem::class);
      }
  }
  </code></pre>
  
  <p>Polymorphic <code>ModuleItem</code> model</p>
  
  <pre><code>class ModuleItem extends Model
  {
      public function typeable()
      {
          return $this-&gt;morphTo();
      }
  
      public function module()
      {
          return $this-&gt;belongsTo(Module::class);
      }
  }
  </code></pre>
  
  <p>Polymorphic relation on Item</p>
  
  <pre><code>class Item extends Model
  {
      public function module_item_types()
      {
          return $this-&gt;morphMany('App\ModuleItem', 'typeable');
      }
  }
  </code></pre>
  
  <p>Polymorphic relation on Enemy</p>
  
  <pre><code>class Enemy extends Model
  {
      public function module_item_types()
      {
          return $this-&gt;morphMany('App\ModuleItem', 'typeable');
      }
  }
  </code></pre>