title: Laravel Eloquent - where created_at is X days ago
body: <p>I have an array of days that I want to check against for trials ending in Laravel Spark:</p>
  
  <pre><code>$trialIntervals = [10, 5, 3, 1, 0];
  </code></pre>
  
  <p>I fetch all teams and then check if their trial_ends_at date one of the intervals using diffInDays:</p>
  
  <pre><code>$daysTillTrialEnds = Carbon::parse($team-&gt;trial_ends_at)-&gt;diffInDays(Carbon::now());
  </code></pre>
  
  <p>I then check if this value is already an existing result in the database and in the intervals:</p>
  
  <pre><code>if ( in_array($daysTillTrialEnds, $trialIntervals) &amp;&amp; !TrialEndingNotification::where('team_id', $team-&gt;id)-&gt;where('days_notified_at', $daysTillTrialEnds)-&gt;count() ) {
  
     // not yet been added to db
  
  }
  </code></pre>
  
  <p>I have a field called 'days_notified_at' that I am using the check if I have already added the row and notified the customer. However that field is never used again and I would rather reference the created_at date and remove the field.</p>
  
  <p>My question is how I essentially do this:</p>
  
  <pre><code>-&gt;where(Carbon::parse('created_at')-&gt;diffInDays(Carbon::now()), $daysTillTrialEnds)
  </code></pre>
  
  <p>Without getting this error: </p>
  
  <pre><code>DateTime::__construct(): Failed to parse time string (created_at) at position 0 (c): The timezone could not be found in the database
  </code></pre>
  
  <p>The aim is that the where will only show rows that have a created_at date that is X days ago.</p>