'新增', self::METHOD_DEL => '删除', self::METHOD_EDIT => '编辑', ]; /** * @throws ModelException */ function addPostHistory($method, $aItem): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null { if(!in_array($method,self::METHOD)) throw new ModelException('addPostHistory method error'); if(!isset($aItem['uuid'])) throw new ModelException('addPostHistory params error'); $aItem['oid'] = $aItem['id']; unset($aItem['id']); $sDateTime = date('Y-m-d H:i:s'); $aItem['created_at'] = $sDateTime; $aItem['method'] = $method; return $this->addItem($aItem); } //获取最新的历史记录(=当前) function findLastPostId($post_id,$col = ['*']): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|null { return $this->newQuery() ->where('oid',$post_id) ->where('method','!=',self::METHOD_DEL) ->orderBy('created_at','desc') ->first($col); } }