数据库样式 int 11

后台add.html:

<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Lotterytime')}:</label>
<div class="col-xs-12 col-sm-8">
<input >
</div>
</div>

edit.html:
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Lotterytime')}:</label>
<div class="col-xs-12 col-sm-8">
<input >
</div>
</div>

有时会发现这种方法提交会导致数据库中只存了4位的年份值,因为添加编辑提交的是:Y-m-d H:i:s样式,系统只能检测到第一个年份,需要后台controller对应的model转换一下

转换代码:
// 追加属性
protected $append = [
'lotterytime_text'
];

public function getLotterytimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['lotterytime']) ? $data['lotterytime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}


protected function setLotterytimeAttr($value)
{
return $value && !is_numeric($value) ? strtotime($value) : $value;
}

相关文章:

  • 2022-12-23
  • 2021-05-14
  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2021-06-04
  • 2022-01-08
  • 2021-09-02
猜你喜欢
  • 2022-01-30
  • 2021-12-24
  • 2022-12-23
相关资源
相似解决方案