title: Multi-Table Inheritance in Laravel Eloquent
body: <p>For writing on a PDF document, the user should be able to create different "modules" that can be reused in several <code>Documents</code>. There are normal modules (<code>Module</code>) having the attributes <code>name, posX, posY</code> and e.g. <code>TextModule</code> which has all the attributes <code>Module</code> has but adds <code>text, font, color, size</code>. This is what you would normally achieve using inheritance.
  I found several ways to build single-table inheritance with Eloquent but this would lead to a lot of <code>NULL</code> values in the database because all <code>Module</code> objects won't have any <code>text, font, color</code> or <code>size</code>.
  Unfortunately, I have not found any multi-table inheritance documentation for Eloquent.</p>
  
  <p>This is what I have so far:</p>
  
  <pre class="lang-php prettyprint-override"><code>class Module extends Model
  {
      protected $fillable = [
          'name', 'posX', 'posY'
      ];
  
      public function document()
      {
          return $this-&gt;belongsTo('App\Document');
      }
  }
  
  class TextModule extends Module
  {
      protected $fillable = [
          'text', 'font', 'color', 'size'
      ];
  }
  </code></pre>
  
  <p>Furthermore, my apporach was to create two migrations (because I need multi-table inheritance) and have every common attribute in the <code>create_modules_table</code> migrations, whereas I have added every "special" attribute to the <code>create_textmodules_table</code>.</p>
  
  <p>My wish is to call <code>Module::all()</code> to retrieve any kind of modules, so <code>Module</code> and <code>TextModule</code> in this example. For every object contained in the returned collection it should be possible to call <code>obj-&gt;document</code> to retrieve the corresponding document (and vice versa for <code>Document::hasMany(Module::class)</code> relationship).
  At the moment I only receive all <code>Module</code> objects when calling <code>Module::all()</code> without any error message. </p>
  
  <p>Am I on the wrong track with my approach?</p>