title: Laravel eloquent model where datetime less than or equal
body: <p>I am having an expire_datetime field in Test model and it has many relationship with Candidate model. I want to get all the tests which exipre_datetime is less than or equeal to now datetime. I am doing like this but I am getting all the records, date comparirion is not functioning.</p>
  
  <p><strong>Test Model:</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>    public function testcandidates()
      {
          return $this-&gt;hasMany(Candidate::class,'test_id','id');
      }
  </code></pre>
  
  <p><strong>TestController:</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>$tests = Test::with([
              'testcandidates' =&gt; function ($query) {
                  $query-&gt;where('result', '=', 'assigned');
               }
           ])
           -&gt;where('expire_datetime', '&lt;=', Carbon::now('UTC'))
           -&gt;get();
  </code></pre>