Laravel 背包进入一个新的时间领域,从 1970 年开始日历
Laravel Backpack Entering a New Time Field Starts Calendar at 1970
在 Laravel Backpack 中创建了一个事件 CRUD 对象。每次我添加新事件时,帮助设置事件时间的日历都会设置为 1/1/1970 12:00 AM。我如何更改该字段以默认为当天 12:00 AM?
1) 对于 datetime
field type:如果您定义 default
,将使用该值。所以你可以这样做:
$this->crud->addField([
'name' => 'datetime',
'label' => 'Datetime',
'type' => 'datetime',
'default' => date("Y-m-d H:i:s"),
]);
2) 对于 datetime_picker
field type,系统会自动预填充当前日期。
希望对您有所帮助。
$this->crud->addField([
'name' => 'datetime',
'label' => 'Date Time',
'type' => "datetime_picker", //use this instead of datetime
'format' => 'M d,Y H:m',
'default' => date("Y-m-d 00:00:00"), //defaults to today at midnight
'allows_null' => true //if you want to allow removal of date picked
]);
在 Laravel Backpack 中创建了一个事件 CRUD 对象。每次我添加新事件时,帮助设置事件时间的日历都会设置为 1/1/1970 12:00 AM。我如何更改该字段以默认为当天 12:00 AM?
1) 对于 datetime
field type:如果您定义 default
,将使用该值。所以你可以这样做:
$this->crud->addField([
'name' => 'datetime',
'label' => 'Datetime',
'type' => 'datetime',
'default' => date("Y-m-d H:i:s"),
]);
2) 对于 datetime_picker
field type,系统会自动预填充当前日期。
希望对您有所帮助。
$this->crud->addField([
'name' => 'datetime',
'label' => 'Date Time',
'type' => "datetime_picker", //use this instead of datetime
'format' => 'M d,Y H:m',
'default' => date("Y-m-d 00:00:00"), //defaults to today at midnight
'allows_null' => true //if you want to allow removal of date picked
]);