如何删除通知错误: - 在codeigniter中最后一个插入id为null时,获取属性非对象?

I am trying to save incremented number by adding into last insert id, but when i save first value into databse table, showing the error like "notice error:-trying to get property non object". I think this error is coming because last insertid is null in table. can anyone help me to remove this error?

Thank you so much

My model:

public function last_id()
{

    $this->db->select('RA_id');
    $this->db->from('rental_agreement');
    $this->db->order_by('RA_id','DESC');
    $this->db->limit('1');
    $query = $this->db->get();
    return $query->row();

}

My controller:-

$insert_id = $this->Rental_agreement_model->last_id();
        $last_id = $insert_id->RA_id;
        if($last_id == 0){
                        $RA_num = 'RA1';
                        }
        else{
                        $RA_num = $insert_id->RA_id;
                        }
        $RA_number = $RA_num+1;
        $RA_number1 = "RA$RA_number";