'Object of class App\Models\KamarModel could not be converted to string in codeigniter

I tried to edit the existing data, but we want to update it, an error occurs. how can i convert this image object to string , so that it can be insert in phpmyadmin

my Controller

public function update($id){
$gambarLama = new KamarModel();
$kamarGambar = $gambarLama->find($id);

$file = $this->request->getFile('gambar');
    if($file->isValid() && !$file->hasMoved()){
        $gambarLama = $kamarGambar['gambar'];
        if(file_exists("images/".$gambarLama)){
            unlink("images/" . $gambarLama);
        }

        $imageName = $file->getRandomName();
        $file->move("images/",$imageName);
    }else{
        $imageName = $gambarLama;
    }

    $data = [
        'nama_kamar'        => $this->request->getPost('nama_kamar'),
        'deskripsi'         => $this->request->getPost('deskripsi'),
        'tipe_kamar'        => $this->request->getPost('tipe_kamar'),
        'harga_kamar'       => $this->request->getPost('harga_kamar'),
        'status'            => $this->request->getPost('status'),
        'fasilitas'         => $this->request->getPost('fasilitas'),
        'gambar'            => $imageName
    ];

    $gambarLama->update($id,$data);
    return redirect()->to('/dataHotel');
}

my routes $routes->post('/editKamar/(:num)', 'Admin::update/$1');



Solution 1:[1]

you need it name of file first then move to upload folder


        if (isset($_FILES['image'])) {

          
            $uploadFolder=ROOTPATH."upload";
                             
            $avatar = $this->request->getFile('image');
            $avatar->move($uploadFolder, time() . '.' . $avatar->getClientExtension());
            $pathStoreToDatabase= $avatar->getName();
            

        }

```
and remember use post method

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 paliz