Skip to content

date field must cast to 'date' in eloquent model with a mysql date field #1114

@Gil-1

Description

@Gil-1
  • Laravel Version: 5.7.15
  • Nova Version: 1.2.0
  • PHP Version: 7.2.12

Description:

When wanting to display a date (not a datetime) field I have the following error

date field must cast to 'date' in eloquent model

I already posted in laracasts nova's channel but there is no solution right now
https://laracasts.com/discuss/channels/nova/date-field-must-cast-to-date-in-eloquent-model-and-it-is

Steps To Reproduce:

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',
    ];

I also tested

protected $casts = [,
        'billed_at' => 'date',
        'payed_at' => 'date',
        'due_date' => 'date',
    ];
  • created_at, updated_at and deleted_at are stored as TIMESTAMP (no issue)
  • 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'),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions