新增数据:
$user =
new
User([
'name' =>
'thinkphp',
'email' =>
'thinkphp@qq.com'
]);
// 过滤post数组中的非数据表字段数据
$user->
allowField(
true)->
save();
// post数组中只有name和email字段会写入
$user->
allowField([
'name',
'email'])->
save();
$user =
new
User;
$list = [
[
'name'=>
'thinkphp',
'email'=>
'thinkphp@qq.com'],
[
'name'=>
'onethink',
'email'=>
'onethink@qq.com']
];
$user->
saveAll(
$list);
$user =
User::
create([
'name' =>
'thinkphp',
'email' =>
'thinkphp@qq.com'
]);
更新数据: