Level 7
Fixed by modifying the Factory a bit
Carbon::today()->toDateString()
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I'm currently trying to make a test which asserts that a record has been stored in the database.
The Environment model has an attribute 'ed_split' which is casted as Carbon date, by defining this on the model:
protected $dates = ['ed_split'];
As this is only a date and not a datetime, it's stored as such in the database
$table->date('ed_split');
In my Factory I create a Carbon instance:
'ed_split' => Carbon\Carbon::now(),
However the assertion fails as the created object has ed_split": "2019-10-06T09:55:42.639743Z"; while the database only has 2019-10-06.
What's the best way to tackle this issue?
Fixed by modifying the Factory a bit
Carbon::today()->toDateString()
Please or to participate in this conversation.