You can use $lastInsertID = $this->db->insert_id(); after insert query.
$lastInsertID = $this->db->insert_id();