Save morphOne polymorphic in database
<p>Using Laravel 5, I got a module class (an Eloquent model). I would like to create subclasses for many kind of module : moduleA, moduleB, etc. Each sub-module have specific attributes and main module class own general attributes. A module belongsTo a Page.</p>

<pre><code>class Module extends Eloquent {

    protected $fillable = ['name', 'slug', 'x', 'y'];

    /*...*/

    public function page()
    {
        return $this-&gt;belongsTo('App\Models\Page');
    }
}

class ModuleA extends Module {
    protected $fillable = ['power'];
    /*...*/
}

class ModuleB extends Module {
    protected $fillable = ['size'];
    /*...*/
}
</code></pre>

<p>In the database SubModules should have all Module attributes and SubModules attributes. Exemple for Module B : 'name', 'slug', 'x', 'y', 'size' and ModuleB should belongsTo a Page.</p>

<p>What is the best way to implement this kind of classes ? </p>

<p><strong>Updade : How can I do to save everything in MySQL ?</strong></p>

<pre><code>class Module extends Eloquent {

    protected $fillable = ['name', 'slug', 'x', 'y'];

    /*...*/

    public function page()
    {
        return $this-&gt;belongsTo('App\Models\Page');
    }
   public function modulable()
   {
        return $this-&gt;morphTo();
   }
}

class ModuleA extends Module {
    protected $fillable = ['power'];
    public function module()
    {
        return $this-&gt;morphOne('App\Models\Module', 'modulable');
    }
}
</code></pre>

<p>Doing a simple $module.save() doesn't store datas of Module and ModuleA (only timestamps) :</p>

<pre><code>$module = new ModuleA();
$m-&gt;save(); // 

&gt; db.module_navs_collection.find();
{ "_id" : ObjectId("56a4a4c6bffebcec068b456a"), "updated_at" : ISODate("2016-01-24T10:17:42.097Z"), "created_at" : ISODate("2016-01-24T10:17:42.097Z") }
</code></pre>