Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date field must cast to 'date' in Eloquent model #22

Closed
Cidro opened this issue Aug 23, 2018 · 4 comments
Closed

Date field must cast to 'date' in Eloquent model #22

Cidro opened this issue Aug 23, 2018 · 4 comments

Comments

@Cidro
Copy link

Cidro commented Aug 23, 2018

I'm getting this errror when using a Date field on a Nova resoruce.
The model associated with the resource already has the "cast" property with the fields needed.

//Fields function on Project Resource
public function fields(Request $request) {
    return [
        ID::make()->sortable(),
        Text::make('Name')->sortable(),
        Textarea::make('Description'),
        Date::make('Start Date'),
        Date::make('End Date')
        BelongsTo::make('Client')
    ];
}
//Casts of the model dates
protected $casts = [
    'start_time' => 'date',
    'end_time' => 'date'
];
@bonzai
Copy link

bonzai commented Aug 23, 2018

Set the column name:

Date::make('Start Date', 'start_time'),
Date::make('End Date', 'end_time')

https://nova.laravel.com/docs/1.0/resources/fields.html#field-column-conventions

@liamcottle
Copy link

You are defining the casts as start_time and end_time but using Start Date and End Date in your fields. You'll need to correct that, or tell the field the correct attributes.

@liamcottle
Copy link

^ bet me to it :')

@Cidro
Copy link
Author

Cidro commented Aug 23, 2018

Ups, my bad.

Thanks for the quick response 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants