How can I query a has-many-through relationship in Laravel
<p>What are some ways to query this type of relationship in Laravel</p>

<p>Tables:</p>

<ul>
<li>Users    </li>
<li>Roles    </li>
<li>Privileges</li>
</ul>

<p>Where: </p>

<ul>
<li>Each role has a set of privileges </li>
<li>Each user can belong to many roles</li>
<li>The User has many privileges through Roles</li>
<li>Users and Roles are related through an intermediate table. So there is no user_id column on the Roles table</li>
</ul>

<p>In effect I'm trying to do something like:</p>

<pre><code>User()-&gt;Roles()-&gt;Privileges()-&gt;get() 
</code></pre>

<p>but I'm not sure of the laravel way to do this</p>

<h3>DB Structure update:</h3>

<pre><code>USERS
   id
   name
   email

ROLES
   id
   role

USERS_ROLES
   id
   user_id (foreign key)
   role_id (foreign key)

PRIVILEGES
   id
   role_id (foreign key)
   privilege

USER belongsToMany Roles
ROLE belongsToMany Users
USER has many privileges through ROLES
</code></pre>