title: Laravel extend or use Traits dynamically
body: <p>It is possible to extend or use different class during run time?</p>
  
  <p>Example:
  Let say we have a <code>model</code> called <code>Player</code> (Our A -model)</p>
  
  <pre><code>&lt;?php
  namespace App\Models;
  use Illuminate\Database\Eloquent\Model;
  
  class Player extends Model{
  
  }
  </code></pre>
  
  <p>And we have 2 other models (<strong>B and C models</strong>)</p>
  
  <pre><code>&lt;?php
  namespace App\Models;
  use Illuminate\Database\Eloquent\Model;
  
  protected $connection= 'db_b';
  
  class PlayerInfoB extends Model{
      function getName(){
          return $this-&gt;name;
      }
  }
  </code></pre>
  
  <p>Our C model</p>
  
  <pre><code>&lt;?php
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  protected $connection= 'db_c';
  
  class PlayerInfoC extends Model{
      function getName(){
          return $this-&gt;name_g;
      }
  }
  </code></pre>
  
  <p>How Model <code>A (Player)</code> can extend <code>Model B or C</code> during run time based on configuration or other data</p>
  
  <p>Why I need this.
  I have a 2 or more different tables, this tables columns have different names, so for example:</p>
  
  <pre><code>Table 1 - name
  
  Table 2 - name_g
  
  Table 3 - name_full
  </code></pre>
  
  <p>So I need a wrapper that I can always call <code>getName()</code>, without checking what table is used now.</p>
  
  <pre><code>$player = Player::get();
  
  echo $player-&gt;getName();
  </code></pre>
  
  <p>If something is not clear, please comment and I will update my question.</p>
  
  <p><strong>Update</strong> based on <a href="https://stackoverflow.com/users/4613398/madalin-ivascu">madalin-ivascu</a> answer can be done this way?</p>
  
  <pre><code>class Player extends Model{
      protected $model;          
  
      public function __construct(){
  
          $this-&gt;setModel();
  
          parent::__construct();
  
  
      }
      protected function setModel(){
          $this-&gt;model = $this-&gt;column_model_name
      }
      function getAttributeName(){
          return $this-&gt;model-&gt;getName();
      }
  
  }
  </code></pre>