title: Test fails because of date time formatting when searching for model in database
body: <p>Since Laravel 5.6, <a href="https://laravel.com/docs/5.6/eloquent-mutators#array-and-json-casting" rel="nofollow noreferrer">Eloquent Date Casting</a> is available.<br>
  So I've got a model <em>MyModel</em> with:</p>
  
  <pre><code>class MyModel extends Model {
      protected $casts = ['from' =&gt; 'date:Y-m-d', 'to' =&gt; 'date:Y-m-d'];
      protected $dates = ['from', 'to'];
  }
  </code></pre>
  
  <p>And the factory:</p>
  
  <pre><code>$factory-&gt;define(MyModel::class, function(Faker $faker) {
      return [
          'from' =&gt; Carbon::instance($faker-&gt;dateTime),
          'to' =&gt; Carbon::instance($faker-&gt;dateTime),
          // some more attributes
      ];
  }
  </code></pre>
  
  <p>In my unit test I'm looking for an instance of <em>MyModel</em>:</p>
  
  <pre><code>/** @test */
  public function example() {
      $myModel = factory(MyModel::class)-&gt;create();
  
      $this-&gt;assertDatabaseHas('my_models', $myModel-&gt;attributesToArray());
  }
  </code></pre>
  
  <p>And that's what I get (excerpt):</p>
  
  <blockquote>
    <p>Failed asserting that a row in the table [my_models] matches the attributes {<br>
    "from": "2019-01-12",<br>
    "to": "2019-02-13",<br>
    }.<br>
    Found: [{<br>
        "from": "2019-01-12 00:00:00",<br>
        "to": "2019-02-13 00:00:00",<br>
    }].</p>
  </blockquote>
  
  <p>Obviously the test fails, because the time is appended at the database record's fields. They are of type <code>date</code>.</p>
  
  <p>I could update the assertion to something like this...</p>
  
  <pre><code>$this-&gt;assertDatabaseHas('my_models', [
      'from' =&gt; $myModel-&gt;from-&gt;toDateTimeString(),
      'to' =&gt; $myModel-&gt;to-&gt;toDateTimeString(),
  ] + $myModel-&gt;attributesToArray());
  </code></pre>
  
  <p>...but that's far away from elegant.</p>
  
  <p>What do I do to make this assertion succeed?</p>