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

GilG's avatar
Level 3

date field must cast to 'date' in eloquent model and it is

Hello,

I cast the date fields as this in the eloquent model :

protected $dates = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s',
        'deleted_at' => 'datetime:Y-m-d H:i:s',
        'billed_at' => 'date:Y-m-d',
        'payed_at' => 'date:Y-m-d',
        'due_date' => 'date:Y-m-d',
    ];
  • created_at, updated_at and deleted_at are stored as TIMESTAMP
  • billed_at, payed_at and due_date are stored as DATE in Mysql

In my Nova Resource, if I use the Date field I have the error

date field must cast to 'date' in eloquent model

And this is how the fields are set

Date::make('Billed At', 'billed_at'),
Date::make('Payed At', 'payed_at'),
Date::make('Due Date', 'due_date'),

What am I missing ?

0 likes
6 replies
rawilk's avatar

What if you tried putting your date only fields into $casts instead?

protected $casts = [
    'billed_at' => 'date',
    ...
];
1 like
GilG's avatar
Level 3

I just tried but same issue

warksit's avatar

Did you get this resolved, just run into the same myself

astemir's avatar

Make your field datetime and try this:

protected $casts = [
    'billed_at' => 'datetime',
    ...
];

Please or to participate in this conversation.