title: Laravel orderByRaw array of user ID with binding
body: <p>So, with my server, there's a scenario where I want to pass an array of ID to my Laravel server to fetch a list of users. At the same time, I want the returned database query results to also maintain the same order as the array of ID params I passed in.</p>
  
  <p>I have the following which currently works:</p>
  
  <pre><code>$strIDs = $request-&gt;input('user_ids');
  $u_ids = explode(",",$strIDs);
  $users = User::whereIn('user_id',$u_ids)-&gt;notDeleted()-&gt;orderByRaw(DB::raw("FIELD(user_id, $strIDs)"))-&gt;get();
  </code></pre>
  
  <p>But I understand there's something called SQL Injection Attack and a recommended thing to do is bind the parameters of a SQL statement with variables to guard against these problems.</p>
  
  <p>Following some other searches, I tried the following but the syntax is incorrect:</p>
  
  <pre><code>$users = User::whereIn('user_id',$u_ids)-&gt;notDeleted()-&gt;orderByRaw(DB::raw("FIELD(user_id, ':values')", ['values' =&gt; $strIDs]))-&gt;get();
  </code></pre>
  
  <p>Can anybody see what I did wrong?</p>