我有一个像下面这样的laravel面板。我试图使用一个日期字段,如下所示:
new Panel('Suggestions', [
Flexible::make('Suggestions')
->addLayout('Suggestions', 'suggestion', [
Text::make('Title'),
Textarea::make('Message'),
Date::make('Date', 'date')
])
->button('Add Suggestion'),
]),但是,它显示了此错误:
{消息:“日期字段必须在雄辩模型中转换为‘日期’。”,异常:“异常”,…。}
例外:“例外”
文件:"/var/www/html/vendor/laravel/nova/src/Fields/Date.php“
线路: 41
消息:“日期字段必须在雄辩的模型中转换为‘日期’。”
我在模型中有这样的强制转换属性:
protected $casts = [
'date' => 'date'
];你知道有什么问题吗?
相对于模型,数据库表中没有date字段。我只是有一个suggestions json字段,其中有很多列,包括"date“列/键,这可能就是问题所在。在这种情况下,你知道如何解决这个问题吗?谢谢
发布于 2022-05-10 14:04:01
把这个添加到你的演员中,而不是‘约会’‘=>’日期‘,这解决了我的问题。
protected $casts = [
'flexible-content' => FlexibleCast::class
];另一个选项是解析它并将其转换为MomentJS格式,这也很好:
DateTime::make('Date')
->format('DD/MM/YYYY HH:mm')
->resolveUsing(function ($value) {
return $value;
}),来源:https://github.com/whitecube/nova-flexible-content/issues/171
发布于 2022-09-25 19:36:19
首先,我想您需要将db字段重命名为其他字段。
然后
您需要像这样将db字段转换到模型中:
//Casts of the model dates
protected $casts = [
'DB_FIELD_NAME' => 'date'
];https://stackoverflow.com/questions/72186944
复制相似问题