title: laravel mysql query with multiple where orwhere and inner join
body: <p>How can I prepare the following MySQL query in Laravel?</p>
  
  <p>This is the code I used without success:</p>
  
  <pre><code>$user_list = DB::table('users')
  -&gt;where('users.user_id' ,'=', $clientId)
  -&gt;where('users.firstname', 'LIKE', '%'.$_POST['name'].'%')
  -&gt;orWhere('users.lastname', 'LIKE', '%'.$_POST['name'].'%')
  -&gt;orWhere('users.email', 'LIKE', '%'.$_POST['name'].'%')
  -&gt;join('users_roles', 'users.id', '=', 'users_roles.user_id')                        
  -&gt;where('users_roles.role_id', '=', Role::USER_PARTICIPANT)
  -&gt;get();
  </code></pre>
  
  <p>The conditions must be:</p>
  
  <ol>
  <li><code>users.user_id == $clientId</code></li>
  <li><code>users.firstname == '%'.$_POST['name'].'%' OR users.lastname == '%'.$_POST['name'].'%' OR users.email == '%'.$_POST['name'].'%'</code></li>
  <li>inner join between users_roles and users crossing by <code>users.id == users_roles.user_id when users_roles.role_id == Role::USER_PARTICIPANT</code></li>
  </ol>