-
Notifications
You must be signed in to change notification settings - Fork 36
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 with a mysql date field #1114
Comments
In the protected $dates = [
'billed_at', 'payed_at', 'due_date'
] But |
I just tried and that doesn't work. Here is what I tried protected $casts = [
'amount' => 'float(10,2)',
'reference' => 'integer',
'billed_at' => 'date',
'payed_at' => 'date',
'due_date' => 'date',
];
protected $dates = [
'created_at',
'updated_at',
'deleted_at',
]; |
I can't confirm. MigrationSchema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->date('premium_expired_at')->nullable();
$table->timestamps();
}); Modelclass User extends Model
{
protected $fillable = ['premium_expired_at'];
protected $casts = ['premium_expired_at' => 'date'];
} Resourceclass User extends Resource
{
public static $model = \App\User::class;
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Date::make('Subscription', 'premium_expired_at')->nullable(),
];
}
} |
Maybe you used mutators for this fields. Attribute casting doesn't work with mutators. |
That was it. I used mutators and that messed everything. |
I came across this issue whilst working on some data importers. public function getPublishedAtAttribute($value)
{
return \Carbon\Carbon::create($value ?? $this->attributes['created_at']);
}` |
Description:
When wanting to display a date (not a datetime) field I have the following error
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 :
I also tested
created_at
,updated_at
anddeleted_at
are stored as TIMESTAMP (no issue)billed_at
,payed_at
anddue_date
are stored as DATE in MysqlIn my Nova Resource, if I use the Date field I have the error
And this is how the fields are set
The text was updated successfully, but these errors were encountered: