模型定义:
<?php
namespace app\common\model;
use think\Model;
class Product extends Model
{
protected $insert = ['insert_date'];
protected $type = [
'insert_date' => 'timestamp'
];
protected function setInsertDateAttr()
{
return time();
}
}批量插入:$model = new Product;
$insert = [];
for ($data as $item) {
$insert[] = [
'title' => $item['title'],
'content' => $item['content'],
'insert_date' => $item['insert_date'], // 这里设置的内容不生效
];
}
$model->saveAll($insert);Model::save() 应该也是如此。想问的是,除了插入之后再手动更新的方案,怎么样让手动设置的内容生效? 最佳答案