Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DevMaster's avatar

Why isn't the 'deleted_at' datetime field auto-casted?

I see (from tinkering with Nova) that the 'deleted_at' datetime field (as generated by $table->softDeletes(); in a migration) is not auto-casted to a DateTime or Carbon instance.

BUT the $table->timestamps(); datetime fields are indeed auto-casted by Laravel: "By default, Eloquent will convert the created_at and updated_at columns to instances of Carbon, which extends the PHP DateTime class".

So I am simply curious to hear if there is any special practical or technical reason to exclude 'deleted_at' from auto-casting?

Many thanks, Dev Master

0 likes
5 replies
arthvrian's avatar

I think because not all developers use soft deleted

however it will be a new feature in 5.8

1 like
DevMaster's avatar

@ARTHVRIAN - Thanks for the news, it does indeed look like 5.8 will change some of the Carbon integrations.

Cronix's avatar
Cronix
Best Answer
Level 67

Because it's optional. You just have to add the trait to the model(s) and $dates array that use it like the docs show:

To enable soft deletes for a model, use the Illuminate\Database\Eloquent\SoftDeletes trait on the model and add the deleted_at column to your $dates property:

https://laravel.com/docs/5.7/eloquent#soft-deleting

1 like
DevMaster's avatar

@CRONIX - Thanks @cronix, the plot thickens. And good to know it's documented nicely! Though I would argure that $table->timestamps(); is also optional. Anyway thanks guys, no problem!

Please or to participate in this conversation.