title: Laravel 5.4 Model Properties and Methods Inheritance
body: <p>The main model is <strong>BaseMonster</strong>, with all the basic informations of a monster (stats, monster type, etc) that will be inherited by child classes.  </p>
  
  <p>At the moment, I have two child classes named <strong>WildMonster</strong> and <strong>PlayerMonster</strong>, related to <strong>BaseMonster</strong> with a one to many relationship (from BaseMonster side).  </p>
  
  <p>My main goal is to be able to <strong>inherit attributes like stats, names and images and all the related methods</strong> from BaseMonster to other child monster classes.<br>
  This way i can <strong>avoid db redundancy</strong> for common attributes and at the same time <strong>adjust various aspect of certain child monsters</strong> just editing theirs parent BaseMonster record.<br>
  <strong>Example</strong>: "Kraken" monster has too high attack stat value. With a simple change to its <strong>BaseMonster</strong> record, all <strong>WildMonster</strong> and <strong>PlayerMonster</strong> instances related to "Kraken" are affected.  </p>
  
  <p>I want to <strong>avoid code redundancy</strong> too, for example making one rating() method in BaseMonster that will use all the actual stats (<strong>along with stat bonuses and levels</strong>) of the monster instance and that can be <strong>used by any of the monster child classes</strong>.  </p>
  
  <p>I tried accessing parent properties with Laravel accessors, and setting them to the <strong>Eloquent base_monster relationship</strong> stat, but this way i can't work with children attributes, <strong>like level or health_bonus</strong> to <strong>adjust values accordingly</strong>. (or at least i didn't find the right way).<br>
  I also tried setting <strong>accessors from child side</strong> with half a success, but anyway this mean i have to write the same accessors in all child classes and to make a huge mess if i want to change something.</p>
  
  <p>How can I achieve something like this in laravel 5.4?</p>
  
  <hr>
  
  <h1>Extract of attributes</h1>
  
  <hr>
  
  <p><strong><em>BaseMonster</strong> is the parent of the other monster classes and contains all the common attributes and methods needed in most of the occasions. <strong>BaseMonsters are created by Game Admin</strong> to manage things like stats and images and to generate new <strong>WildMonster</strong> to populate various <strong>Dungeons</em></strong>.</p>
  
  <p><strong>BaseMonster</strong> (extends <strong>Model</strong>)  </p>
  
  <ul>
  <li><strong>name</strong></li>
  <li><strong>image</strong></li>
  <li><strong>health</strong></li>
  <li><strong>attack</strong></li>
  <li><strong>defense</strong></li>
  <li><strong>monster_type_id</strong> (relationship with the MonsterType model)  </li>
  </ul>
  
  <hr>
  
  <p><strong><em>WildMonster</strong> is the monster encountered in dungeons or in other ways. Can "transform" to PlayerMonster if recruited</em>.  </p>
  
  <p><strong>WildMonster</strong> (extends <strong>BaseMonster</strong>)  </p>
  
  <ul>
  <li><strong>name</strong> (to customize name for special encounters)</li>
  <li><strong>level</strong> (to adjust stats accordingly)</li>
  <li><strong>health_bonus</strong> (there is a chance a monster has various stats bonuses)</li>
  <li><strong>attack_bonus</strong>  </li>
  <li><strong>defense_bonus</strong>  </li>
  <li><strong>base_monster_id</strong> (relationship with the BaseMonster model)</li>
  </ul>
  
  <hr>
  
  <p><strong><em>PlayerMonster</strong> is the monster recruited by the player after a battle</em>.  </p>
  
  <p><strong>PlayerMonster</strong> (extends <strong>BaseMonster</strong>)  </p>
  
  <ul>
  <li><strong>name</strong> (eventually customized by the player)</li>
  <li><strong>level</strong></li>
  <li><strong>health_bonus</strong></li>
  <li><strong>attack_bonus</strong>  </li>
  <li><strong>defense_bonus</strong>  </li>
  <li><strong>base_monster_id</strong> (relationship with the BaseMonster model)</li>
  </ul>
  
  <hr>