title: Laravel 5.2: Syntax errors after converting raw query to eloquent using converter tool
body: <p>I've converted the below raw query to eloquent using <a href="https://jjlabajo.github.io/SQLtoEloquent/" rel="nofollow noreferrer">https://jjlabajo.github.io/SQLtoEloquent/</a> but there seems to be a couple of syntax errors.</p>
  <p><strong>RAW</strong></p>
  <pre><code>$messages = DB::select(DB::raw(&quot;SELECT COUNT(*) AS count FROM messages as m WHERE conversation_id IN ( SELECT id FROM conversations WHERE (user_one = {$id} AND delete_user_one = 0 AND (m.created_at &gt; user_one_convo_deleted_at OR  user_one_convo_deleted_at IS NULL) AND (m.created_at &gt; user_one_msgs_deleted_at OR user_one_msgs_deleted_at IS NULL)) OR (user_two = {$id} AND delete_user_two = 0 AND (m.created_at &gt; user_two_convo_deleted_at OR user_two_convo_deleted_at IS NULL) AND (m.created_at &gt; user_two_msgs_deleted_at OR user_two_msgs_deleted_at IS NULL) ) ) AND is_seen = 0 AND user_id &lt;&gt; {$id} AND user_id NOT IN ( SELECT user_id FROM deactivateaccount ) AND ( user_id NOT IN ( SELECT id FROM users WHERE flag = 0 AND id = user_id ) OR user_id IN ( SELECT id FROM users WHERE membershiptype IN ('admin','premium','free-premium','diamond') AND id = user_id ) ) AND (hard_delete = 0 OR hard_delete IS NULL) AND (deleted_from_receiver = 0 OR deleted_from_receiver IS NULL)  AND (isflaged IS NULL OR isflaged != 1) AND m.created_at &gt;= '{$past_period_months}' ORDER BY created_at DESC&quot;));
  
  return $messages[0]-&gt;count;
  </code></pre>
  <p><strong>ELOQUENT</strong></p>
  <pre><code>DB::table(&quot;messages as m&quot;)
      -&gt;select(&quot;count (*) as count&quot;)
      -&gt;whereIn(&quot;conversation_id&quot;, function($query){
      $query-&gt;from(&quot;conversations&quot;)
      -&gt;select(&quot;id&quot;)
      -&gt;where(&quot;(user_one&quot;, &quot;=&quot;, {$id}]
      -&gt;where(&quot;delete_user_one&quot;, &quot;=&quot;, 0)
      -&gt;where(&quot;(m.created_at&quot;, &quot;&gt;&quot;, user_one_convo_deleted_at)
      -&gt;whereNull(&quot;user_one_convo_deleted_at&quot;);
      })
      -&gt;where(DB::raw(&quot;where_subquery_group_3_)&quot;))
      -&gt;where(DB::raw(&quot;(user_two = {$id} and delete_user_two = 0 and (m.created_at &gt; user_two_convo_deleted_at or user_two_convo_deleted_at is null)&quot;))
      -&gt;where(&quot;is_seen&quot;, &quot;=&quot;, 0)
      -&gt;where(&quot;user_id&quot;, &quot;&lt;&gt;&quot;, {$id})
      -&gt;where(DB::raw(&quot;( user_id not in ( select id from users where flag = 0 and id = user_id )&quot;))
      -&gt;whereIn(&quot;user_id&quot;, function($query){
      $query-&gt;from(&quot;users&quot;)
      -&gt;select(&quot;id&quot;)
      -&gt;whereIn(&quot;membershiptype&quot;, &quot;('admin',&quot;);
      })
      -&gt;where(&quot;id&quot;, &quot;=&quot;, user_id)
      -&gt;where(DB::raw(&quot;(hard_delete = 0 or hard_delete is null)&quot;))
      -&gt;where(DB::raw(&quot;(deleted_from_receiver = 0 or deleted_from_receiver is null)&quot;))
      -&gt;where(DB::raw(&quot;(isflaged is null or isflaged != 1)&quot;))
      -&gt;where(&quot;m.created_at&quot;, &quot;&gt;=&quot;, {$past_period_months})
      -&gt;orderBy(&quot;created_at&quot;,&quot;desc&quot;)
      -&gt;get();
  </code></pre>
  <p><a href="https://i.stack.imgur.com/QA2ok.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QA2ok.png" alt="Here's a screenshot of the errors" /></a></p>
  <p>Why are there errors and how do I fix them? Thank you</p>