Skip to content

从3.0移植,出现了使用模型修改器的问题 #826

@xyc113

Description

@xyc113

请教下,不知道是我设置不对还是什么问题
举个例子,比如:
数据库有字段 num new_num
在model是这么设置根据num设置new_num

public function setNewNumAttr($value, $data)
{
return $data['num'] + 1;
}

然后在entity这么设置,获取前台修改的num
public function save($data){
$this->num = $data['num'];
$this->new_num = $data['new_num'] ;
return $res = $this->save();
}

在controller这么设置,前端就传了num值过来

$data = input();
$user = UserEntity::find(1);
$user->save($data);

我代码是从3.0移植过来的,在3.0上这样是没问题的
在4.0要改成$this->force()->save();才会保存到数据库,然后还产生个问题,加了force()后,update_time不自动写入了

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions