title: Using Auth to get the role of user in a pivot table
body: <p>I have the following database structure a users &amp; roles table joined using a pivot table:</p>
  <p>The users table contains all the info such as email and password, while the roles table defines the different roles :</p>
  <p><strong>roles table</strong></p>
  <ul>
  <li>1 -&gt; admin</li>
  <li>2 -&gt; encoder</li>
  <li>3 -&gt; salesman</li>
  <li>4 -&gt; tech</li>
  </ul>
  <p>Now the roles are defined many-to-many because, there are some encoders that are assigned also as an admin. Others may have an salesman+admin role, or even encoder+salesman. Basically it multiple roles can be assigned to someone.</p>
  <h2>Table Structure</h2>
  <p><strong>users</strong></p>
  <ul>
  <li>id</li>
  <li>email</li>
  </ul>
  <p><strong>roles</strong></p>
  <ul>
  <li>id</li>
  <li>role</li>
  </ul>
  <p><strong>role_user</strong></p>
  <ul>
  <li>id</li>
  <li>role_id</li>
  <li>user_id</li>
  </ul>
  <p>I know that if I do</p>
  <pre><code>$user = User::find(1)-&gt;email;
  return $user;
  </code></pre>
  <p>the result would display the email of the user with ID 1.</p>
  <p>I was trying to do <code>$user = Auth::user()-&gt;roles;</code> so that it will get the role of the currently authenticated user.</p>
  <p>But doing so returns a JSON which displays all the roles the user is assigned to.</p>
  <p>I was hoping to use this in a filter, to do something like this</p>
  <pre><code>$user=Auth::user()-&gt;roles;
  if($user == 'admin')
  {
      //do something
  }
  else
  {
      //you are not an admin
  }
  
  if($user == 'encoder')
  {
      //do something
  }
  else
  {
      //you are not an encoder
  }
  </code></pre>