Laravel返回UTCDateTime而不是Carbon实例。 为什么?

I have a model that has the following in it:

protected $dates = ['created_at','modified_at','deleted_at', 'my_date'];

The same model is embedded in another document (using Mongo).

Now when I try to get the min and max dates in the model by doing:

 $minDate = $doctor->cases()->min('embedded_doc.my_date');
 $maxDate = $doctor->cases()->max('embedded_doc.my_date');

What I am getting are instances of UTCDateTime and not Carbon. The documentation states that if I list the date in the $dates array it would return Carbon instances. I am not clear. What am I missing?

It is happening because when you run min or max query it returns the single value, not an object of the Model.

That's why it's not converted into Carbon.

You can also write your query as:

$doctor->cases()->orderBy('my_date')->select('my_date')->first()->my_date;

This will give the Carbon object.