addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { $this->id = $this->getRandId($this->user_id); $this->expired_at = strtotime('+30 days'); $this->created_at = time(); } public function beforeUpdate() { $this->updated_at = time(); } protected function getRandId($userId, $prefix = 'RT') { return md5("{$prefix}-{$userId}" . time() . rand(1000, 9999)); } }