title: Laravel 5.1 Invalid datetime format: 7 ERROR: invalid input syntax for type date error
body: <p>I've been having trouble with eloquent that keeps returning error. Below is the query that i tried to run in laravel.</p>
  
  <pre><code>$actives = ProjectVersion::join('version_employees as ve', 've.report_id' ,'=', 'project_versions.id')
          -&gt;join('employees as e', 've.employee_id', '=', 'e.id')
          -&gt;whereBetween(\DB::raw("'1985-05-27'::date"),[
              \DB::raw("to_date(timeline-&gt;&gt;'start_time', 'YYYY-MM-DD')"),
              \DB::raw("to_date(timeline-&gt;&gt;'release_time', 'YYYY-MM-DD')")])
          -&gt;groupBy('e.name')
          -&gt;select(\DB::raw('count(e.id), e.name'))
          -&gt;get();
  </code></pre>
  
  <p>Now this returns an error of</p>
  
  <pre><code>Invalid datetime format: 7 ERROR: invalid input syntax for type date: "to_date(timeline-&gt;&gt;'start_time', 'YYYY-MM-DD')" 
  </code></pre>
  
  <p>The full query returned by the error message is</p>
  
  <pre><code>SELECT count(e.id), e.name 
  FROM "project_versions" inner join "version_employees" as "ve" on "ve"."report_id" = "project_versions"."id" inner join "employees" as "e" on "ve"."employee_id" = "e"."id" 
  WHERE '1985-05-27'::date 
       BETWEEN to_date(timeline-&gt;&gt;'start_time', 'YYYY-MM-DD')      
       AND to_date(timeline-&gt;&gt;'release_time', 'YYYY-MM-DD') 
  GROUP BY "e"."name"
  </code></pre>
  
  <p>The thing is that when i run this query in pgadmin, it runs fine and returns the result that i wants.</p>
  
  <p>I've been stuck for hours debugging this. Any idea on where the problem is ?</p>