You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use the TimestampableExtension and I use in my Entity the trait LaravelDoctrine\Extensions\Timestamps\Timestamps.
I want to use Carbon ; following the documentation, I added a custom_type in the the custom_types key of the doctrine.php config file:
'datetime' => Carbon\Doctrine\DateTimeType::class,
// Also works..
// 'datetime' => DoctrineExtensions\Types\CarbonDateTimeType::class,
As expected, when I query the database using the entity manager, my createdAt / updatedAt property (or any other property of type DateTime) is of type Carbon. Great!
BUT if I instantiate a new Entity and persist it as follow:
$foo = new Foo();
$entityManager->persist($foo);
$foo->getCreatedAt() // DateTime
Both createdAt and updatedAt are of type DateTime. So it was set using DateTime and not Carbon..
How can I have it to be of type Carbon instead of DateTime? The reason I'm asking is because while writing unit tests, I want to be able to travel back and forth in time using Laravel travel() sugar or just by doing Carbon::setTestNow(now()->subDays(2)); so when I create/persist my entity the created_at value will be automatically of what was set as "now" in the test since it uses Carbon end-to-end.
The text was updated successfully, but these errors were encountered:
Hi,
I use the
TimestampableExtension
and I use in my Entity the traitLaravelDoctrine\Extensions\Timestamps\Timestamps
.I want to use Carbon ; following the documentation, I added a
custom_type
in the thecustom_types
key of thedoctrine.php
config file:As expected, when I query the database using the entity manager, my
createdAt
/updatedAt
property (or any other property of type DateTime) is of typeCarbon
. Great!BUT if I instantiate a new Entity and persist it as follow:
Both
createdAt
andupdatedAt
are of type DateTime. So it was set using DateTime and not Carbon..How can I have it to be of type Carbon instead of DateTime? The reason I'm asking is because while writing unit tests, I want to be able to travel back and forth in time using Laravel
travel()
sugar or just by doingCarbon::setTestNow(now()->subDays(2));
so when I create/persist my entity thecreated_at
value will be automatically of what was set as "now" in the test since it uses Carbon end-to-end.The text was updated successfully, but these errors were encountered: