protected function set_iid() { $max = $this->where('project_id', $this->project_id)->max('iid'); $this->iid = $max + 1; }