title: How to extend a Users model with another many to many relationship models Skills/Levels?
body: <p>I am trying to extend a User model with associated Skills and Levels.  Where all users will have different skill levels for a variety of skills.  Im trying to figure out the most efficient way to setup the relationships to accomplish this.</p>
  
  <p>Im currently setting Skill to Level as a many to many relationship. User to skills_has_levels is one to many but of no current use.</p>
  
  <p>There are many skills a user can have and each skill can have a different level from no experience to expert.</p>
  
  <pre><code>[Tables]
  
  users
      id, username, email, pwd, token, timestamps
  
  skills (ie. laravel, angular, bootstrap, etc)
      id, name, order
  
  levels (ie. none, beginner, intermediate, expert)
      id, name, value
  
  skills_has_levels
      id, skills_id, levels_id, users_id
  </code></pre>
  
  <p>We have three models:</p>
  
  <pre><code>1) User (has many skills with levels)
  2) Skill (has many levels)
  3) Level (has many skills)
  </code></pre>
  
  <p>In the Skill model: (to have the users_id available: unused)</p>
  
  <pre><code>$this-&gt;belongsToMany('App\Level’)
          -&gt;withPivot(‘users_id’);
  </code></pre>
  
  <p>To list all users, their skills, and levels :</p>
  
  <pre><code>$users = User::all()-&gt;toArray();
  
  foreach($users as $user)
  {
      echo "User ID: ".$user-&gt;id;
      $skills = Skill::where(‘users_id’, ’=‘, $user-&gt;id)-&gt;get()-&gt;toArray();
      print_r($skills);
      echo "\n\n\n";
  }
  </code></pre>
  
  <p><strong>Ultimately, I would want the User model to return a skills/levels array of all the associated user skills &amp; their levels: skill name, skill order, level name and level value.</strong></p>
  
  <p>What I currently do works but i feel it could be done better.</p>
  
  <p>whats the best way to structure the relationships for the User model to connect to skills names and the associated levels values?</p>
  
  <p>Is it possible to related the Skill/Level directly to the User model? So i only have to use the User model to access all of the associated skill and levels.</p>
  
  <p>Or are my relationships wrong? Could change the models to this relationship:</p>
  
  <pre><code>A User has many Skill
      Skill has many skill types
      Skill has many skill levels
  </code></pre>
  
  <p>Thanks in advance.</p>